1

I have some javascript in a template and when I try to use template variables inside the ... tags, the template variables are not parsing.

All other template vars on the page are parsing as expected.

I also have $config['protect_javascript'] set to "n"

Code in template:

<script type="text/javascript">
$('#{pricing_button}{pricing_button_attr_id}{/pricing_button}').on('click', function (e) {
    e.preventDefault();
    alert('clicked it!');
    alert('{ga_event}');
});
</script>

The rendered page results:

<script type="text/javascript">
$('#{pricing_button}{pricing_button_attr_id}{/pricing_button}').on('click', function (e) {
    e.preventDefault();
    alert('clicked it!');
    alert('{ga_event}');
});
</script>
2
  • 1
    I assume {pricing_button} is wrapped in {exp:channel:entries} or something and renders outside of the JS tags? Try setting a var first and not have the tag curlies in the JQuery: var target = '#{pricing_button}{pricing_button_attr_id}{/pricing_button}'; $(target).on ... etc. Commented Oct 20, 2015 at 8:19
  • That was it. Sigh. I had it outside the {exp:channel:entries} block. Thank you :) Commented Oct 21, 2015 at 21:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.