Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

pulling language var value inside js

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Mon Jan 26, 2015 8:46 am    Post subject: pulling language var value inside js Reply with quote

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
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Mon Jan 26, 2015 9:16 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jan 26, 2015 11:22 am    Post subject: Reply with quote

Without using AJAX, you can use autoescape functionality of Smarty3.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP