We want to implement HighCharts in our custom Joomla module. Since it's a Javascript library, do we attach it to the view as a reference to the script files? I've also read about a PHP wrapper for HighCharts. Is it advisable to use it instead of the direct Javascript library?
To embed Javascript files into a Joomla module, you need to use the following code:
$document =& JFactory::getDocument();
$document->addScript(JURI::root() . "modules/mod_your_module/file.js");
$document->addScript(JURI::root() . "modules/mod_your_module/file2.js");
...
If you need to write custom Javascript, then you will need to write it like so:
$js = 'alert("alert message");';
$document->addScriptDeclaration($js);
Hope this helps.
Related
I need a advice on how to add some different views/tmpls to a Joomla 3.x System Plugin. I made a simple plugin to replace Joomla 3.x Offline page, but i would like to add several different views (layouts) to that plugin. I am confused with views vs tmpl. Could some one give me some guidance and give me a simple directory structure to follow.
I use this code to trigger \views\defaultview\view.html.php but i want to have more different views. Is this the correct way?
public function onBeforeRender(){
// Get the application.
$app = JFactory::getApplication('site');
if (($app->getCfg('offline'))&&(!$app->isAdmin())) {
// Get the document object.
$doc = JFactory::getDocument();
$view = 'defaultview';
$basePath = __DIR__;
$config = array( 'base_path'=>$basePath);
require_once $basePath . DS . 'views' . DS . $view . DS . 'view.html.php';
JResponse::setHeader('Content-Type', 'text/html; charset=utf-8');
JResponse::sendHeaders();
$app->close();
}
}
Thanks. Regards.
You don't provide much information (e.g. Joomla version, code showing what you've tried etc) but here goes…
Views and tmpls are part of the MVC of Joomla components not plugins. Plugins are small pieces of code that respond to events. If you're not clear on them read the linked articles.
Having, said that, it is possible to affect the loading of a view or it's tmpl but how you want to use it will depend on your existing code. Depending on whether you're on Joomla 3.x or Joomla 2.5.x you will probably benefit from reading through the tutorials about developing an MVC component, the 2.5.x version here or the 3.x version here.
Tmpl files are effectively templated pieces of code that are loaded by the view, a tmpl file can also load a sub-tmpl file easily. e.g. /tmpl/default.php can load /tmpl/default-tools.php with a single call (originally they were meant to be flexible and reusable pieces of code but for various reasons that doesn't work in practice). They can be overridden by the template in use for any given page.
In the recent releases of the J3 line, layouts are now available. These are small, flexible pieces of code that can be used and re-used in various places through-out Joomla, and they can be provided by third-party extensions, and overridden at the template.
If you can provide more details about your particular usage scenario, code etc we can probably provide more help.
Failing that as this question is about Joomla specific implementation details, you may get a better result if you, try asking on the Joomla Q&A StackExhange site.
I want use my library function in controller file. Is it possible ? Thanks..
Not sure what you mean. If by that you mean "Can I write my own libraries and call them from a controller in CodeIgniter", the answer is yes.
I suggest take a look at this page in the CodeIgniter documentation for further details.
I'm trying to build a module for joomla 1.5 which basically need to load my javascript file to the part of each webpage.
I've googled all possibilities and tried every way I read in the joomla docs and nothing succeeded.
It's very easy to add javascript to the body but I want to add it to the part of the code.
Thanks
You should not insert the javascript directly into the head tag, since it will not be able to be compressed and combined with other scripts. And also, since it is hard coded into the head tag, you will have to manually add/edit/remove it for every possible template.
Just put this into the module code:
<?php
$document = &JFactory::getDocument();
$document->addScript( '/path/to/my.js' );
?>
If you want your javascript to be added to every page, you will have to publish your module on every page. It is probably a better idea to write a plugin using the above code sample.
You should be able to put something into your index.php file (although not recommended because IIRC it will be overwritten when you update your Joomla (which you should be doing)):
<script type="text/javascript" src="<?php echo $this->baseurl ?>/media/system/js/myjavascript.js"></script>
That should get your script added to every page where you want it.
*Edit: that was only for getting JS to load on every page - for modules you'll have to use a plugin of some sort.
Something like THIS may help I think...
Although, I'm still moderately unclear as to where/how you're looking to implement your JS.
I'm trying to implement a contact form into a website I'm making. Nobody recommends to just include the php file into a template.
I don't understand how to make or convert an existing contact form to one working with Smarty.
Any guidelines ?
Well, the purpose of smarty is to seperate your code logic from your design template.
So in your contact form, instead of using echo, you should write the output to smarty variables. I.e:
$smarty->assign('email', $email);
At the end of your contact forms PHP you should then load the smarty template
$smarty->display('index.tpl');
I would advice you to read the smarty best practices page as well. It gives detailed information on how smarty templates should be used (and also why not to include plain PHP).
I don't want to remove smarty templates from controllers. In some actions of controllers, I want to use default view system of codeigniter, while on other actions, I want to keep SMARTY templates as display medium. How can I achieve this?
Thanks in advance
I've been developing a CI Smarty library for Codeigniter. It lets you use default Codeigniter views and lets you render Smarty templates using the Codeigniter template parser as I am extending it.
Here is the repository: https://github.com/Vheissu/Ci-Smarty
As it stands, it works really well. If you have any problems, log an issue on Github and I'll fix it usually within 24 hours. Other solutions are mostly outdated, my library lets you use new Smarty 3 features like template inheritance, etc.
Look in the CodeIgniter Wiki - http://codeigniter.com/wiki/Smarty/
And a thread in the official forum:
http://ellislab.com/forums/viewthread/60050/