how to send a template variable into Javascript

Discussion forum for MOD Writers regarding MOD Development.
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

how to send a template variable into Javascript

Post by techman41973 » Fri Sep 18, 2015 12:06 am

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-----

User avatar
Registered User
Posts: 372
Joined: Thu Nov 07, 2013 7:12 pm

Re: how to send a template variable into Javascript

Post by peopleopinion » Tue Sep 29, 2015 1:24 am

Try the following:

Code: Select all

<script type="text/javascript">
   var r="{TOPIC_TITLE}";
   [your code goes here]
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.
Please explicate why you voted negative or positive, so it will be possible to better understand each one's point of view.
Please visit and vote my website and express freely your opinion on it (phpbb ver.: 3.0.12):
Thanks. Best Regards, peopleopinion.


Return to “[3.0.x] MOD Writers Discussion”