footer extra content - attribute

Permalink
I want to move .js scripts into the footer rather than having them load in the header. by default blocks load their js files in the header.

So i have moved the required js files into the root /js folder, and want to be able to add a footer extra content on the pages where the extra js files are required. This should speed up the initial page loading time.

I can see the attribute for Header Extra Content and i want o be able to add another for footer extra content to be placed at the bottom of the footer just before the
</body>
</html>

can anyone help me create such a custom attribute?
or ideally edit the block to load their js after the
<?php Loader::element('footer_required'); ?>
Thanks
This is for concrete5.5.1

ecomatt
 
ecomatt replied on at Permalink Reply
ecomatt
Can no one help me with this - or have I posted in the wrong forum?
Steevb replied on at Permalink Reply
Steevb
If you can get to the elements folder of your theme on your server you can paste what you want in the footer.php.
ecomatt replied on at Permalink Reply
ecomatt
I realise this - but I don't want it on every page.
sure I could then create a page type for the pages I want the js to load and then create another footer.php (with another name) in the elements folder which gets loaded by that new page type - but there surely is a limply way to add a custom Attribute that would allow you to add a Footer Extra Area enabling you to add the custom scripts page by page.
Steevb replied on at Permalink Reply
Steevb
So why not put a editable area in your footer?

<?php $a = new Area('MyCode'); $a->display($c); ?>
mkly replied on at Permalink Reply
mkly
I actually use and work on a "theme engine" that does break out the javascript. I use it to run the javascript and css though minify. I also does put the javascript in the footer it they were added with the html helper.

You need to pull out the javascript and add it to the footer before you called header_required.php

To get you started can do something like this in your theme header.php file above Loader::element('header_required.php')
$items = $this->getHeaderItems();
javascripts = array();
foreach($items as $key => $item) {
  if($item instanceof JavaScriptOutputObject) {
    // I'm not sure if this will "just work"
    // let me know
    // You might have to do something with
    // the html helper and $item
    $this->addFooterItem($item);
    unset($items[$key]);
  }
}


Anyhow, I have no idea if that actually works as is. But if you give it a shot, please let me know as it would help in what I'm doing.
cainKuri replied on at Permalink Reply
cainKuri
im looking for the same thing... did you found it ?
SoulDesigns replied on at Permalink Reply
SoulDesigns
If you are still working on this here is my take on the issue. Today I was looking to do the same thing because I cam across and issue with a jQuery pluggin that disabled my ability to edit a page.

Now I know about and have coded a script that allows me to add to the
<?php Loader::elements('header_required'); ?>

What my script would allow me to do was whenever I was logged into the site it would disable the jQuery pluggin.

This got me to thinking. What if I could do the same for the footer_required. So I went into the Concrete5 main directory and added my script on line 9 of the page. I wanted the same effect like with the header_required.

So if you need to have a script run at the bottom of the page.
You should grab a copy of the footer_required.php found in the main directory and add it to your directory within your elements folder to override to core version.

Another way around this is to create a file called extra_footer.php and place it in your elements folder of your theme and create a clone of the page_type you want it on and call to it like this;

<?php $this->inc('elements/extra_footer.php'); ?>


and place under your <?php Loader::elements('footer_required'); ?>

I abuse this method a lot for sub content areas on sites that I build using C5.

Hope my tale was helpful :P
cainKuri replied on at Permalink Reply
cainKuri
The answer of SoulDesigns help ? is it working? did you try it ?...

thank you in advance.
losttheplot replied on at Permalink Reply
I spent some time on this issue as I wanted to get all of my JS down into the footer. I already have a conditional in place to load the latest jquery if the user is not logged in, and I fully intended to treat each scenario independently. I started with mkly's suggestion and got it working inside header_required.php like this:
// split HeaderItems into css and js so that the js can be displayed in the footer.
$this->footer_js = '';
$this->header_css = '';
$items = $this->getHeaderItems();
foreach($items as $item) {
  if (is_a($item, 'JavaScriptOutputObject')) {
    $this->footer_js .= '    '.$item.'
';
  } else {
    $this->header_css .= '    '.$item.'
';
  }
}
// was: print $this->controller->outputHeaderItems();
echo $this->header_css;

Then down in the footer I added this:
echo $this->footer_js;

This worked fine per se, but I then discovered that both Nivo Slider and a lightbox script I use require their js to be loaded in the head, after jquery, so that scuppered my plans! Had this not been an issue I would have then reintroduced $this->controller->outputHeaderItems() inside a login conditional.