How to include external js file in joomla 3.8 - php

How to Including external js file in joomla 3.8 in different articles and modules.
Thanks in advance..!

There are two ways to include a JavaScript file using the Joomla API. The first is to use the JDocument class of the addScript method:
<?php
$document = JFactory::getDocument();
$document->addScript('/media/system/js/sample.js');
?>
2-
The second uses the JHTML class of the script method
<?php
// Add the path parameter if the path is different than 'media/system/js/'
JHTML::script('sample.js', 'templates/custom/js/');
?>
API has changed in 3.x, so the second parameter cannot be a string. If you really need to use this method, you must include the absolute link to your JavaScript file:
<?php
JHtml::script(Juri::base() . 'templates/custom/js/sample.js');
?>
hope this help you .

Related

Include independent project to the codeigniter view

Is there any possible to include the independent project as a browser in separate catalog/server into codeigniter view?
For example:
<?
include 'www.yahoo.com';
?>
Try including this in your view
<iframe class="iframe_element" src="https://www.example.com"></iframe>
Be sure to apply style to your .iframe_element to make it the size and position that works best for you.

Generating PDFs from template files using wkhtmltopdf

I need to generate PDF files from HTML templates and plan on using wkhtmltopdf to do that. Inside the HTML templates, I need to be able to use PHP logic to adjust what the template will render. Take this HTML template for example:
<p>Dear <?php echo $firstname; ?>,</p>
<p>Thanks for signing up. You've invited these people along with you:</p>
<ul>
<?php foreach ($invitees as $invitee): ?>
<li><?php echo $invitee; ?></li>
<?php endforeach; ?>
</ul>
<p>Regards,</p>
<p>Chris White</p>
I have no problem being able to pass a HTML template file to wkhtmltopdf but I don't know how to get the PHP logic inside it to run correctly and be able to return the resulting template. I came across this blog post while Googling but the author uses Smarty as a template language: https://davejamesmiller.com/blog/php-html-pdf-conversion-using-wkhtmltopdf
Using Smarty would solve my problem but I don't want to bring in a library to do this when I can just use plain old PHP. Basically, I need a way to pass in variables to the HTML template (in this case $firstname and $invitees), have it execute the PHP code inside the template and then return the resulting template after the PHP has been executed.
Any ideas?
Just save your file as php (for example template.php) and implement there the logic you need.
I did the same also with wkhtmltopdf and it worked great.
I also passed some variables over GET to the template to really get the correct report as pdf.
To save the file I used the PHP session id and saved the file to a folder with write permissions for www-data (Linux) and started the download automatically via Javascript.
I had the same need and I did it like that. Don t really know if my code will help you but why not.
First I used composer to get https://github.com/mikehaertl/phpwkhtmltopdf.
lets say you have a php file " content.php "
<?php
echo "<html>";
echo "<h1>test</h1>";
echo "<html>";
?>
your index.php will be :
<?php
require "vendor/autoload.php";
ob_start();
require('content.php'); //The php file
$content = ob_get_clean();
$pdf = new \mikehaertl\wkhtmlto\Pdf($content);
if (!$pdf->send()) {
throw new Exception('OMG WHY : '.$pdf->getError());
}
If you're not using any template engine, can't u just call your template.php file with some params ?
Something like
$wkhtml2pdf->html2pdf('template.php?firstname=Foo');
(I have no idea how wkhtml2pdf works, this code is just for you to understand the logic)
and in your template.php file :
<p>Dear <?php echo $_GET['firstname']; ?>,</p>

Is it possible to call PHP in html?

I have a PHP that returns some HTML code, for example, if I execute this in the browser,
http://www.myserver.com/myscript.php?size=300
this will return some html code like this,
'<div><img src="..." /></div>'
I am wondering if it's possible I can call this php script in my html code directly? For example, if I want to use the output from the PHP script in my Wordpress sidebar widget?
You can use file_get_contents() like this:
<div class="sidebar">
<?php
$html = file_get_contents("http://www.myserver.com/myscript.php?size=300");
echo $html;
?>
</div>
If your Current page's extension is not php, you cannot call php in it directly.
You have to use some javascript/jquery/ajax to run the php file externally and load the data into a class or id using one of those javascript based code.
If your current page is already a php file than,you can use include(); or require(); functions and it does the job.
above answers are correct, but that might be not concerned for wordpress, that are of core php functionality.
i have a different way for sidebar use, that's provide by wordpress already.
it is an inbuilt functionality, please take a look towards my answer.
Show active sidebar in Wordpress
How to make wordpress sidebar
you can found ::
try this one, it is different way of using sidebar
[1] put your all "left_bar"(sidebar) code in a new file named "sidebar-left_bar"
[2] save it with header.php, function.php and all files (saving location)
[3] now just use <?php get_sidebar( 'left_bar' ); ?> where you want to use
Thanks

Including a uri "/user/sidebar" page (Kohana Framework) in PHP

I would like to have the page on user/sidebar on the right in the template design.
Normally, I would include a php file. But I am using Kohana Framework so I have created a view and a controller for this sidebar, and exists on mysite.com/user/sidebar
Now how would i <?php include "/user/sidebar"; ?> correct? I get no such file og dir error for this. I tried full url, but allow_url_include=0
Just looking through the Kohana documentation...
It seems like you can include a "request" inside a view with the following command.
<?php echo Request::factory('user/sidebar')->execute() ?>
See this page for more info: http://kohanaframework.org/3.0/guide/kohana/mvc/views
AndrewR's comment is close. For Kohana 3.2, you'll want to load a view within a view and not a request within a view:
<?php echo View::factory('/user/sidebar'); ?>
or
<?php include Kohana::find_file('views', 'user/sidebar') ?>
Either is acceptable to do.

How to switch layout files in Zend Framework?

I'm sure it's a simple one-liner, but I can't seem to find it.
How can I use a different layout file for a particular action?
Update: This worked for me, thanks!
// Within controller
$this->_helper->_layout->setLayout('other-layout') //other-layout.phtml
//Within view script
<?php $this->layout()->setLayout('other-layout'); ?>
From inside a Controller:
$this->_helper->layout->setLayout('/path/to/your/layout_script');
(via these docs)
EDIT: I should mention that the path is relative to whatever your layout directory is (by default, it's application/layouts/scripts/)
You can also use like this
// Within controller
Zend_Layout::getMvcInstance()->setLayout('layout_name');
//Within view script
<?php $this->layout()->setLayout('layout_name'); ?>
Your layout must be in /layouts/scripts/ folder, otherwise you need to specify the path also. No need to write .phtml, just name of the layout

Categories