Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Template variable in configuration string.

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
mataniko
Smarty n00b


Joined: 31 Jul 2018
Posts: 3

PostPosted: Wed May 01, 2019 3:20 am    Post subject: Template variable in configuration string. Reply with quote

Is there a way to expand a variable referenced in a configuration string? For example:

Code:

// sample.php
$smarty->assign(array( 'release' => '2.0.0' )

// sample.ini
info=Version {$release}

// sample.tpl
<span>{#info#}</span>


Output
Code:
<span>Version {$release}</span>


Desired output:
Code:
<span>Version 2.0.0</span>


Thank you
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Wed May 01, 2019 11:08 am    Post subject: Reply with quote

That's inadvisable but possible.
Code:
{include "string:{#info#}"}
Back to top
View user's profile Send private message
mataniko
Smarty n00b


Joined: 31 Jul 2018
Posts: 3

PostPosted: Wed May 01, 2019 1:07 pm    Post subject: Reply with quote

Thanks. I was hoping there was a more straightforward way to do this, one which wouldn't require the template writer to know which string variable has a string variable in it.

Would this be something considered for a future version? If so, I'd look into making a PR for this.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Fri May 03, 2019 6:37 am    Post subject: Reply with quote

No. Configuration settings are variables.
Template can't possible know which variables contain other vriables, or it would blow up from infinite recursion.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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