$context['html_footers']

Started by Arantor, March 10, 2010, 07:38:31 PM

Previous topic - Next topic

Arantor

Right now there is a construct, $context['html_headers'] that can be populated with items to add into the theme in the <head> block and can be done as a source level edit, so it works on almost all themes with minimal support issues.

I'd like a similar construct for the footer, to inject content just before </body> in the html_below subtemplate (IIRC, at least) so that for scripts that load JS files that don't need to be available on page load, or ideally should be triggered at the end of loading, e.g. Google Analytics, they can be done without modifying the template.

It'd simplify all the mods that add JS items to the page (analytics mods, 'weather' mods, plus some of the stuff I have in mind for AJAX which would be better served inline at the end of the page, not the start)
Holder of controversial views, all of which my own.


JBlaze

Jason Clemons
Former Team Member 2009 - 2012

Arantor

Also, while I'd normally argue that 2.0 is feature-locked etc, I'd actually be inclined to argue this one is not really a feature per se, it's a tweak that completes what's already there.

All it would have to be is:

Load.php, find:
// Some basic information...
if (!isset($context['html_headers']))
$context['html_headers'] = '';


Add after:

if (!isset($context['html_footers']))
$context['html_footers'] = '';


And index.template.php (Curve, probably same for Core, not checked)
Code (find) Select
echo !empty($settings['forum_width']) ? '
</div>' : '', '
</body></html>';
}


Code (replace) Select
echo !empty($settings['forum_width']) ? '
</div>' : '', $context['html_footers'], '
</body></html>';
}


You don't even have to alter the list of variables called into scope in template_html_below since it already adds it (not sure why anything other than $settings is there though...)
Holder of controversial views, all of which my own.


Nick Whetstone

The artist formerly known as (Ha)²

Former Support Specialist

Please do not solicit support via PM. Here's why!

vbgamer45

Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

vicram10

+2

I like the idea, is something missing and it would be very necessary and useful

digger


Arantor

I just discovered something.

While researching the integration hooks, I randomly discovered that in RC3 at least, there is actually a variable that amounts to this: $context['insert_after_template']

It does basically the same job and is called as far as I can tell by the theme system prior to template_footer being used. I was looking for it in the template, but it's there in the theme system in Subs.php (obExit function), assuming ;xml isn't in the URL (which is sensible)

Go forth and add footer code! (Yes, this means you could use it to add Google Analytics Code totally without touching the theme)
Holder of controversial views, all of which my own.


Joshua Dickerson

Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

Advertisement: