|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
durangod Smarty Regular
Joined: 10 Feb 2011 Posts: 39
|
Posted: Mon Jan 26, 2015 8:46 am Post subject: pulling language var value inside js |
|
|
Hi im trying to pull the value of the language file var inside js to use it in a validation statment.
i have tried this in the template file in my js section
Code: |
var answer = {$lang.anti_bot_answer};
|
but obviously it does not like that. I do have my js wrapped in literal, is it the syntax that is the issue?
Thanks
update:
i did some poking around a bit more and found a few things but
Code: |
answer = "{$lang.anti_bot_answer|escape:javascript}";
alert('hello'+ answer);
return (false);
|
just returns hello{$lang.anti_bot_answer|escape:javascript} |
|
Back to top |
|
durangod Smarty Regular
Joined: 10 Feb 2011 Posts: 39
|
Posted: Mon Jan 26, 2015 9:16 am Post subject: |
|
|
got it, you have to close the literal just before the smarty var and then reopen it right after like so.
Code: |
answer = {/literal}{$lang.anti_bot_answer|escape:javascript}{literal};
|
works, is there a better or more preferred way? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|