Footer Required - Where Are The "Footer Items" Loading From?

Permalink
Hi All,
I'm hoping I can get someone to tell me how to change which scripts load in the footer. Specifically, their load ORDER. I see in footer_required there's this code:
print $this->controller->outputFooterItems();


I've done an exhaustive search of the controller files but can't find an array or list of any kind.

What I'm trying to do is load a script but it needs to load after others to avoid an error. So, I need to change the order of these footer items.

Thanks,
Michael

View Replies:
bbeng89 replied on at Permalink Reply
bbeng89
In your view or in footer_required you can do

$this->getFooterItems();


And that will return an array containing everything that will be added to the end of the document before the </body> tag, including things that have been added using
$this->addFooterItem();


Does that help you out?
mdm172 replied on at Permalink Reply
Hi bbeng89,
Thanks for the response.
I don't really need to just see the array as viewing the page source shows me that. I really need to add 2 scripts in a place specific place. (Right after Jquery.ui.js)

What I would like to find out is where "footer_required" gets the footer items FROM and change it's pecking order there.

Seems to be a very elusive bit of code.

I hope this makes sense.

Thanks,
Michael
bbeng89 replied on at Permalink Reply
bbeng89
Well I'm sure there is a better way of doing this, but by getting the array of items to be output you can change the order the items are output. So if you override the footer_required.php file by copying /concrete/elements/footer_required.php into /elements/footer_required.php you could do something like this in footer_required.php:
<?php 
$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) {
   echo Config::get('SITE_TRACKING_CODE');
}
//print $this->controller->outputFooterItems();
foreach($this->getFooterItems() as $item){
   echo $item; //this will add the script to the page
   //if the current item is jquery ui then add the two additional scripts
   if(strpos($item, 'jquery.ui.js') !== false){
      echo 'SCRIPT 1';
      echo 'SCRIPT 2';
   }
}
?>


Like I said, there might be better ways of doing this but I was just trying to show that you can modify the way the footer items are output by overriding the footer_required file.
mdm172 replied on at Permalink Reply
Hmmm,

Clever!
I'll try this tomorrow and let you know.

Thanks
mdm172 replied on at Permalink Reply
bbeng,
Thank You so much for your help, but because some pages need this and some can't have this in there, your method is unworkable in my case. I've decided to go with a hard coded alternative method.

Now: A rant (although no one but you will see it apparently)

Open source CMS is a blessing and a curse. It's helps so many people build great sites that they ordinarily would be unable to build. But, without a profit motive, they lack a cohesive support strategy and documentation is truly lacking.

Where does this file get it's information from? Such a simple question for the people who wrote it to answer.
How do I change the JS loading order in the footer? Such a simple but important question.
Has no one ever loaded a dependent script without it's parent?

Concrete5 is the best built OS CMS program out here IMO. I had my HTML5/CSS3 static site up and running in 8 hours. That's amazing to me.
I'm ONLY complaining about the lack of documentation and support from the one's who built it. The subject of this topic was unambiguous. The devs should pop in and reply "it's right here in XYZ file". That's not an unreasonable request. There are topics in here from 2-3 years ago that have NEVER had a reply. That's just sad.

I'm done ranting and I'm gonna go finish my site now.

Thanks
Michael
zutautaz replied on at Permalink Reply
I can see it's and old thread and kinda solved, but just can't pass by your choise to take "hardcode" path...

If the only left problem left is few pages that need includes and few that can't have. Then add custom page attribute to pages that requires extra includes. For example create checkbox attribute "requires_custom_footer_include" and assign it to these pages.

In footer_required add:
<?php 
$_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) {
   echo Config::get('SITE_TRACKING_CODE');
}
//print $this->controller->outputFooterItems();
$currentPage = Page::getCurrentPage();
$needCustomIncludes = $currentPage->getAttribute("requires_custom_footer_include");
foreach($this->getFooterItems() as $item){
   echo $item; //this will add the script to the page
   //if the current item is jquery ui then add the two additional scripts
   if($needCustomIncludes && strpos($item, 'jquery.ui.js') !== false){
      echo 'SCRIPT 1';
      echo 'SCRIPT 2';
   }