I use codeigniter with smarty.
I have a variable stored in the db called $serverName
. I want to expand it to its actual value "Pedrosite"
. But when the page is loaded, it displays exactly {$serverName}
and not the value.
So I found this solution on stackoverflow, using smarty's fetch function:
$data['content']
contains the text from the database.
$data['content'] = $this->CI->smarty->fetch('string:'.$data['content']);
With that, I can display the smarty vars, like: {$smarty.const.FCPATH}
But none of my custom $vars
while they can be shown in a regular template (.tpl
).
So I found this workaround that looks very hacky to me:
$this->CI->smarty->assign('serverName', $this->CI->config->item('server_name'));
I can put this in one of my __construct
function and then it will affect the whole site, and then it loads properly. But I'm not sure it's the right way to proceed at all.