solved Jquery in TPL Help

Dazed
Dazed
@dazed
9 years ago
1,022 posts
Aside from the literals, does this need to me modified when using it in a tpl file? I am throwing an error but it works fine if I run it from an html page.

Thanks!


{literal}<script>
		jQuery(function() {

			jQuery('#audio4_html5_white').audio4_html5({


updated by @dazed: 09/06/16 03:18:27PM
michael
@michael
9 years ago
7,768 posts
presuming you have the closing {/literal} at the other end of it then nothing needs to be done.

if you have things like
.......auddio4_html5({var a=5
thats fine for javascript, but smarty sees {v and thinks "looks like its a smarty function :)". you can get around it by making sure you have a space between any { and the first thing after it { var a=5 would be fine.
Dazed
Dazed
@dazed
9 years ago
1,022 posts
Thanks Michael. It looks like I have some jquery collisions happening. Appreciate the help.
michael
@michael
9 years ago
7,768 posts
The only time where wrapping the whole block in a {literal}{/literal} is a bad idea is when you have javascript and smarty mixed.

Like this:
function someFunction(){
   var a = '{$profile_name}';
   alert(a);
}

If you wrapped that in a literal

{literal}
function someFunction(){
   var a = '{$profile_name}';
   alert(a);
}
{/literal}
instead of getting an alert with 'dazed' the alert would read '{$profile_name}' because smarty couldn't do the replacement.

-- edit --
jamroom uses $ for jquery. so make sure you're not introducing another copy of jquery along with your scripts. you only need it once per page.

and try replacing to $


{literal}<script>
		$(function() {

			$('#audio4_html5_white').audio4_html5({


updated by @michael: 06/03/16 08:56:18PM
douglas
@douglas
9 years ago
2,797 posts
Instead of using literal tags, you can also use ldelim and rdelim in place of the curly brackets... ie.

<script>
jQuery(function() {ldelim}
	some jQuery code here....
{rdelim}....

Hope this helps.


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
Dazed
Dazed
@dazed
9 years ago
1,022 posts
Thanks guys - I have it working. I ended up loading it to a new tpl file and then pulling off the js calls until I found the offending ones. Appreciate the help.