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

config file to javascript (json ?)

 
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
krodelabestiole
Smarty n00b


Joined: 05 Jul 2011
Posts: 4

PostPosted: Sun Nov 27, 2011 6:54 pm    Post subject: config file to javascript (json ?) Reply with quote

i was trying to figure out how to pass variables i get in an INI file to javascript (i'm interested in passing a language file here)

i thought of many way to do this but none worked yet (javascript ini parser i.e.).

I think a quite simple way to achive this would be to pass variables thru json using javascript

my config file is dynamicaly load using
Code:
{config_load scope="global" file="lang/`$smarty.session.lang`.txt"}

(using a session variable)

this works fine

now i've tried codes such as :

Code:
<script type="text/javascript">
   lang = {$smarty.config|@json_encode};
</script>


or

Code:
<script type="text/javascript">
   {foreach from=$smarty.config item=data}
      {$data}
   {/foreach}
</script>


but i still get this warning :
Quote:
Missing argument 1 for Smarty_Internal_Data::getConfigVariable()


is there a way to loop on variables i get from a config file for example ?
or do you think of any total different way to do that ?

any help appreciated !

thanks !
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Nov 27, 2011 8:47 pm    Post subject: Reply with quote

$smarty.config is not a real array of the config variables.
There is no direct way to loop over all config variables from within the template.

But you can create such array at PHP scrip level and assign that array to a Smarty template variable.

See http://www.smarty.net/docs/en/api.config.load.tpl and http://www.smarty.net/docs/en/api.get.config.vars.tpl
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