Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Help:
javascript_href doesnt work in all templates
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/13/13 01:41 
I have a module smarty function which uses jrCore_create_page_element to add javascript_href.

The js links appear in the head when I place the smarty function in jrBlog item_list.tpl or similar.

But do not appear when I place the smarty function in a template such as profile_footer.tpl or just inside the body in header.tpl, the scripts do not appear in the head.

Is this the way it is supposed to be or is it not working correctly?
Do smarty functions that add js and css only do so from within a module template not a skin template?

Thanks


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 04/13/13 06:44 
The problem is that by the time the core "sees" the function in the skin template, it has already processed all of the smarty template variables that are going to be included, so it can't go back and add your href to the meta.tpl file. Instead, you want to define the JavaScript as a module feature in your module's init function - you can check the $_post in your init function if you only want to include the JavaScript on specific views or templates.

Let me know if that helps.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/13/13 09:01 
Thanks Brian, but javascript_href doesn't work with registering a module feature.

I need to link to google maps api scripts, and only want it to appear in the head when there is a map on that page. I am probably overlooking something obvious, but I still can't see it.

A map is created using a smarty function which can be placed in any template depending on what is being mapped (map is a custom field, so could be attached to a jrBlog item in item_list.tpl, or the jrProfile item in the skin profile_footer.tpl, or just in the site footer with hardcoded coordinates, depending on what the site is choosing to show maps for).

Any ideas?


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 04/13/13 09:07 

SteveX:
Thanks Brian, but javascript_href doesn't work with registering a module feature.

I need to link to google maps api scripts, and only want it to appear in the head when there is a map on that page. I am probably overlooking something obvious, but I still can't see it.

A map is created using a smarty function which can be placed in any template depending on what is being mapped (map is a custom field, so could be attached to a jrBlog item in item_list.tpl, or the jrProfile item in the skin profile_footer.tpl, or just in the site footer with hardcoded coordinates, depending on what the site is choosing to show maps for).

Any ideas?


It does work - just register the full URL - i.e.


Code

jrCore_register_module_feature('jrCore','javascript','YourModule','http://site.com/javascript.js');


You can use an if/else check in your init() function if you need to selectively include it.

Let me know if that helps.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/13/13 09:18 
Ah, it does work like that Very Happy Thankyou!

But I still don't see how I can selectively include it - there's no way of knowing what a website will want to map or where they will use the smarty function.

Any ideas?


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 04/13/13 09:21 
I think in that case you'll just need to include it on all pages - if you are worried it will "break" on pages where there is no map (i.e. it has a ready function assuming a DOM element), wrap the entire js in a try/catch block and that will fix that.

Let me know if that helps.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/13/13 10:23 
Ok, thanks.

Do you think something like this would also work?

Within the smarty function, check if its a skin template,
If it is then check if the google script has been loaded (it has a flag),
If it hasnt already been loaded then add the <script tag to the html, and set the flag so it doesnt appear a 2nd time if there are further maps later in the page.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 04/13/13 10:25 
If you can figure that out, then it would work - the problem is that the meta.tpl file has already been processed by the time it gets to your smarty function call. You can of course do it inline in the page (or add it in the footer) and that should work.

Hope this helps!

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/13/13 11:04 
I'll give it a try.

I've found why sending js to the footer wasn't working:

This is from footer.tpl in elastic, flashback and nova:

Code
{if isset($javascript_footer_function)}
<script type="text/javascript">
        {$javascript_ready_function}return true;
</script>
{/if}

{$javascript_ready_function} should be {$javascript_footer_function}


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 04/13/13 12:34 

SteveX:
I'll give it a try.

I've found why sending js to the footer wasn't working:

This is from footer.tpl in elastic, flashback and nova:

Code
{if isset($javascript_footer_function)}
<script type="text/javascript">
        {$javascript_ready_function}return true;
</script>
{/if}

{$javascript_ready_function} should be {$javascript_footer_function}


Good catch - I'll get that fixed up.

Thanks!

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 04/14/13 02:43 

SteveX:
Within the smarty function, check if its a skin template,
If it is then check if the google script has been loaded (it has a flag),
If it hasnt already been loaded then add the <script tag to the html, and set the flag so it doesnt appear a 2nd time if there are further maps later in the page.


This works pretty well!


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Help

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.