Reputation: 2760
I want to put the name of a variable inside a string, so that I can later define the variable, before the string is evaluated to become the value of the variable. How can I do this?
A few different attempts:
{assign var="test" value="$foo"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: Undefined index: foo
{assign var="test" value="{$foo}"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: Undefined index: foo
{assign var="test" value="\{$foo}"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: Undefined index: foo
{assign var="test" value="\$foo"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: $foo
{assign var="test" value="{\$foo}"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: Syntax error
{assign var="test" value="\{\$foo}"}
{assign var="foo" value="bar"}
{eval var=$test}
Result: \bar
Upvotes: 0
Views: 293
Reputation: 2760
Found the solution: Using single quotes!
{assign var="test" value='{$foo}'}
{assign var="foo" value="bar"}
{eval var=$test}
Result: bar
Upvotes: 1