• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Using attributes within a js <script>

PeterC66

New member
Messages
2
Likes
0
Points
1
#1
I have a universal snippet for some js code within a <script> tag. It is essentially:
HTML:
<script>new juicebox({configUrl : 'Jbox-D01992.xml'})</script>
If I put [wbcr_snippet id="4883"] in my webpage it works fine.

I want to make the config an attribute so I have changed the snippet to
HTML:
<script>new juicebox({configUrl : 'Jbox-' + $jboxid + '.xml'})</script>
, and added an attribute of jboxid

and the shortcode in the webpage to [wbcr_snippet id="4883" jboxid="D01992"]

This does not work and the message is Uncaught ReferenceError: $jboxid is not defined

I have got this sort of thing working fine with php snippets. There is probably some simple thing about the universal snippet I am not understanding.

Thanks for a great plugin.
 

alexkovalev

Program developer
Staff member
Messages
175
Likes
11
Points
18
#2
Hi,

Try this code:
JavaScript:
<script>new juicebox({configUrl : 'Jbox-<?= $jboxid ?>.xml'})</script>
Best regards, Alex
 

PeterC66

New member
Messages
2
Likes
0
Points
1
#3
Thanks. It works. I realise now this is just a php program generating a js script as its html output.
(Note to self - <?= $jboxid ?> is shorthand for <?php echo $jboxid; ?> - and this just echos the value of the variable into the script.)