Trying to use HeadJS in Joomla. I added a code to my template - it grabs the javascript files in the head output, prepares a string to output them between head.js code, then removes all javascript files from joomla's head output tag.
The problem is that some scripts are loaded after the template. For example, a module will enqueue some script files after the template has loaded, so its files appear outside of my head.js code. Any ideas how I can control this?
$data = $this->getHeadData();
if( $data['scripts'] ){
foreach ($data['scripts'] as $url=>$type){
if( !strstr($url, 'ajax.googleapis.com/ajax/libs/jquery') )
$headjs[] = $url;
}
unset( $data['scripts'] );
$data['scripts'][$template . '/js/head.js'] = array(
'mime' => 'text/javascript',
'defer' => false,
'async' => false);
$this->setHeadData($data);
}
And then...
<script>
head.js(
<? foreach($headjs as $script): ?>
'<?=$script?>',
<? endforeach; ?>
function(){
}
);
</script>
Different extensions can hook up to different events that are triggered during processing the output (so even after template is rendered).
Best option I found so far is creating system plugin and moving it's order to be the last of available system plugins.
Now you have two options:
use onBeforeCompileHead event (I guess introduced Joomla 1.5.23) to move scripts to headjs.
use onAfterRender event and parse head html code so it's loaded using headjs.
This is fine if you play around with async scripts loading where you have total control over the website, but it's almost impossible to implement as universal extension for Joomla. Some extensions use inline scripts in head, some in the the html body and you'd have to preserve order of execution (simple example: Mootools have to load first).
I use to load asynchronously only those scripts which I've included myself (in my template or my extension). Any scripts that are added with Joomla core (Mootools, core.js, etc.) or other extensions I don't touch.
Related
I'm trying to integrate Codeigniter and Filterable but I cant find much information about it. I have a page with many results and I want to filter the results, for example by the column "name" or "id". I have worked with Filterable before, but never had to do it with Codeigniter.
I tried to put the files on the root. Also in the folder "Application", even tried putting it on the same folder as the view. But in any of these cases I cannot link the files and get it to work.
The ways I've been trying to link the scripts are the following:
<script src="<?php echo site_url('src/filterable.js')?>"></script> This was with the scripts in application folder
<script src="./src/filterable.js"></script> Scripts on root
<script src="<?php echo site_url('admin/src/filterable.js')?>"></script> Scripts on view folder
Is there another way to achieve this? Or maybe another library I could use for it?
Here is how I like to deal with assets.
I create an helper called assets_helper in application/helpers/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('js'))
{
function js($nom)
{
return '<script src="' . base_url() . 'assets/js/' . $nom . '.js" type="text/javascript" ></script>';
}
}
//This is only the part that handle js as it is what's bothering you
Here is the full helper I use : http://pastebin.com/ujETEXJ4
After that, at the same level as index.php I create those folder :
|-Application
|-System
|-index.php
|-Assets
|- css
|- sass
|- images
|- js
Put all the js file you need in your new js folder.
In my application/config/autoload.php I add my new helper
$autoload['helper'] = array('assets', ...);
Finally, in the footer of my page(s) :
<?= js('myjsfile'); ?> //I did not forgot the extension, it's how it works :)
Which will give at the end :
<script src="http://www.example.com/assets/js/myjsfile.js" type="text/javascript" ></script>
Thanks AdrienXL for your answer. I tried to follow your suggestion but in the end I couldn't make it work. For some reason Codeigniter didn't recognize the files I tried to reach.
So after a long searching I ran across a library called Datatables http://www.datatables.net/ it has the option to load the scripts locally or remotely, so just added the link to the scripts needed to the type of filter I had to implement and in the end this last option was what allowed me to make the filters work.
I have a Joomla site, and I want to remove a the footer div from a page without it affecting it on the other pages. Please is there a way I can do it.
You have a couple options - you should be able to set additional CSS on that article to hide the particular footer div for that one individual page without issue.
Additionally you could install a plugin like Sourcerer that allows for PHP coding directly into articles in Joomla! (which comes in REALLY handy!); then you could remove it programmatically as well if necessarily.
Alternatively - you could create a template override for that particular template/page and edit the PHP there to reflect appropriate course of action for that URL/Page.
I tried to list them in order of easiest to most difficult.
It´s not a clean method to hide template-elements by using CSS (display:none). And for your intension you dont´t need a external plugin.
Try a page-option in your template index.php.
First - to get page-options work:
<?php $pageoption1 = JRequest::getVar( 'Itemid', '' ); $pageoption2 = JRequest::getVar( 'page', '' ); $pageoption3 = JRequest::getVar( 'option', '' ); ?>
And further:
<?php if ($pageoption1 == '1') { ?>
This text will be visible only in the page with Menu Item ID 1
<?php } ?>
This works lately in Joomla 2.5.X - for newer version i think it will also work fine.
Joomla by default renders its system messages (errors, notices etc.) in
libraries/joomla/document/html/renderer/message.php.
For my own template, I would like to customize the way these messages are displayed. However it does not seem to be possible in the traditional way, using template overrides.
Is anyone here aware of a way to accomplish something like this?
For Joomla! 1.7 - 2.5
You need copy libraries/joomla/document/html/renderer/message.php in to templates/YOUR_TEMPLATE/html/message.php
Then in index.php of YOUR_TEMPLATE you need to include the file (as it is not automatically included like other overrides):
// Message overwrite
require_once JPATH_ROOT .'/templates/'. $this->template .'/html/message.php';
Now you can safety overwrite the JDocumentRendererMessage::render() function there ;)
For Joomla! 3.x
You just need make html/message.php file in YOUR_TEMPLATE. This file should contain function renderMessage(). Check the isis default template, as example.
Templates overrides only work with the MVC - i.e. views and module chrome.
Without hacking the core all you can do is control what HTML tags are wrapped around the <jdoc:include type="message" /> tag in the template and the CSS defined for the elements of the message block.
A more elegant way to include your override in the template directory is to include the file in a system plugin:
public function onAfterInitialise() {
$app = JFactory::getApplication();
if ($app->isSite()) {
$template = $app->getTemplate();
if (!class_exists('JDocumentRendererMessage') && file_exists(JPATH_THEMES . '/' . $template . '/html/message.php')) {
require_once JPATH_THEMES . '/' . $template . '/html/message.php';
}
}
return true;
}
http://extensions.joomla.org/extensions/style-a-design/popups-a-iframes/26551
OR
http://extensions.panchsoft.com/product/1-popup-system-messages.html
Use this extension for default messages for Joomla.
I'm using HMVC and calling modules in a view. In some cases however, the modules appear before the Doctype! It seems to be caused by calling more than one module into a page but i have instances when i have done this without this happening.
i'm parsing the modules I want to display from the controller into the view
like:
$data['modules'] = array(
'controller/function',
);
$this->load->view('page', $data);
then in the view
foreach($modules as $module){ ?>
<div>
<?php echo modules::run(module); ?>
</div>
<?php }
these divs print fine, and remain where they are supposed to, but for some reason the module jumps before doctype. I've checked that all divs in the whole page are closed, for interfering code in the two modules etc but still at a loss
I've never come across this before, can anyone help?
Thanks :)
This is linked to this post and i fixed it by setting the third parameter to TRUE and echoing the view like this
echo $this->load->view('account_managers', $data, TRUE);
I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>