php - Smarty: how to evaluate string as a variable -


itemprop = "text">

variable assigned to my template {$ testVariable_123}, where 123 auto is generated and also in the form of the {$ autoValue template} Work assigned}

So in my template I want to get the value of variable above

  {Assign var = "Other value" value = "testVariable_" | Cat: $ autoValue}  

So if I print {$ anotherValue} instead of the price, then I get string 'testVariable_123'

Any help appreciated ...

{$ testVariable_123}
You can call {/ P>

The problem is, There was no way to do this well.
Whatever looks good does not work and is not an option. This work is ugly.

Perhaps you will consider some changes in your application design?

Here's how to work:

  # File.php: $ smarty- & gt; Assign ("Autwale", 123); $ Smarty- & gt; Assign ("testVariable_123", "foo"); // Option 1 $ smerty-> Assign ("Other value", "{\ $ testVariable_123}"); // Option 2 $ Smarty-> Assign ("RB", '}'); // hack, to get the correct bracket} Pars it wisely // option 3 $ smartri-> Assign ("mask", '{$ testVariable_% s}'); // full string_format php # directly passed "mask" directly from file.tpl 1) PHP uses $ anotherValue: Plain: {$ anotherValue} Evaled: {eval var = $ anotherValue} 2) String only on clever: {Assigned var = "yetAnotherValue" value = $ autoValue | Plain_format: "{$ $} $ trueVerable_% s $ rb"} plain: {$ yetAnotherValue} Evaled: {eval var = $ yetAnotherValue} 3) String Build using mask from php: {allocated var = "enoughOfValue" value = $ autoValue | Plain_format: $ mask} Plain: {$ enoughOfValue} Evaled: {eval var = $ enoughOfValue}  

Mostly, the problem is that clever one closing bracket} or $ variable will not be ignored , Even if it's in the middle of the string. Running with \ N does not work

You try.

  {allocated var = "yetAnotherValue" value = "{\ $ testVariable_ $ autoValue}"}  

It is clever as "end" Consider the statement:

  will not pay attention to allocated = "yetAnotherValue" value = "{\ $ testVariable_ $ AutoValue}  

and this $ Although it will evaluate the test variable, it should be escaped.
So we will end up with {\ 123 : value (

) I stumbled upon whatever problem I tried. If you find a better way Please make sure you share it here :)


Comments