Question

I'm new to Smarty and now playing with it and see what it can do. I stumble upon this situation, and did not find any reference in documentation: If I have multiple sections in test.conf file,

sitename = "Testing Smarty"
[basic]
apply = true
denied = false
[images]
width = 60px
height = 80px
[anythingelse]
foo = "Yes"
bar = "No"

how can I include all of these sections at once?

If I put:

{config_load file="test.conf"}

Smarty will return only variables, which are not in any sections. Therefore {$smarty.config.sitename} or #sitename# will work, but any other variable will not be loaded.

If I put:

{config_load file="test.conf" section="basic"}

Smarty will return variables, which are not in any sections and adds all variables in "basic" section.

Is it possible to add all sections at once? Or do I have to call

{config_load file="test.conf" section="some_section"} 

for every section I have in configuration file?

Was it helpful?

Solution

According to documentation it's not possible. There's no info you can load multiple config sections. However if you could load config files not in template itself but in PHP as in documentation, http://www.smarty.net/docs/en/api.config.load.tpl , you can create array of sections and then in loop load sections you want, so you should achieve what you want:

$sections = array('section1', 'section2', 'section10');

foreach ($sections as $section) {
    $smarty->configLoad('filename.conf', $section);

}

It should work but I haven't tested it (never needed such functionality and at the moment don't have any smarty project to test)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top