Page 1 of 1

how to send a template variable into Javascript

Posted: Fri Sep 18, 2015 12:06 am
by techman41973
how to send a template variable into Javascript

In overall_footer.html I have a javascript snippet that interfaces to a a web analytics package (named Statcounter)
I'd like to pass a template variable specifically - {TOPIC_TITLE) into my Javascript snippet.
Is there a way I can do this?

<script type="text/javascript">
----JavaScript Snippet - Statcounter Analytics-----
</script>

Re: how to send a template variable into Javascript

Posted: Tue Sep 29, 2015 1:24 am
by peopleopinion
Try the following:

Code: Select all

<script type="text/javascript">
   var r="{TOPIC_TITLE}";
   [your code goes here]
</script>
Explication:
1) The second parenthesis you used into the variable is round: phpbb template vars need curly brackets for both opening and closing vars;
2) The {TOPIC_TITLE} is just "a placeholder". for a string value and will be parsed by phpbb parser on the server and replaced with the corresponding string got form the DB so you must insert it into quotes or it will generate an invalid code that could fire an error.

Also at this address it is possible to find the source of this tutorial (in ita) with an image reporting a working example result. Hope it helps.