how to send a template variable into Javascript

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

how to send a template variable into Javascript

Post 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>
User avatar
peopleopinion
Registered User
Posts: 372
Joined: Thu Nov 07, 2013 7:12 pm
Contact:

Re: how to send a template variable into Javascript

Post 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.
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):
http://peopleopinion.altervista.org
Thanks. Best Regards, peopleopinion.
Locked

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