Reputation: 5819
In my PHP application, I am using Smarty for templating and use some custom functions. In the below example the function name is "text" which takes the "key" attribute. This function will get the string value based on the key
The below example works fine without issues.
{text key='isearch+login_name'}
What I am trying to do is to pass a value dynamically to the attribute. In the below code the variable $plugin will have the dynmaci value and want to be substituted.
{text key='isearch+$plugin_plugin'}
With the above code, I get the output as 'isearch+$plugin_plugin' and not the correct string value.
PHP function for the Smarty function is below.
function smarty_function_text($params, $smarty)
{
$key = $params['key'];
unset($params['key']);
$key = explode('+', $key);
return OW::getLanguage()->text($key[0], $key[1], $params);
}
Upvotes: 1
Views: 738
Reputation: 30531
A solution with cat
filter:
{text key="isearch+"|cat:$plugin|cat:"_plugin"}
Alternatively, you can just add the string in double quotes and mark the variable part with inner quotes:
{text key="isearch+`$plugin`_plugin"}
Upvotes: 2