0

I am not sure if this is possible but I have a variable assigned in a file I cannot change.

$smarty->assign('signature',$account->options[SIGNATURE]);

It is just set to 1 or 0 but I need that value later in the file I am working in. From a settings page I have an array that will validate a signature field based on this value. This is inside of a foreach loop and I was hoping I could do something like {if ${$settings.signature} eq 1} where {$settings.signature} would evaluate to signature.

In php it is basically variable variables I believe. How can I do this in smarty?

1 Answer 1

1

Just add a $:

{$settings.$signature}

will return $settings[0] if $signature is 0

If instead what you need is the value of $settings0:

{$settings{$signature}}

read the Smarty documentation for more info about variables

Sign up to request clarification or add additional context in comments.

9 Comments

Sorry my question is kinda confusing. $settings.signature will evaluate to the string 'signature' so this can be done for multiple settings of different names. I can build the array with these names to access each one
I don't really understand what you mean. Can you write a simple example of the contents of $settings?
$settings[] = array('category'=>'General', 'roles'=>array(STANDARD),'type'=>'bool','label'=>'Signature Pad', 'signature'=>'signature');
so... maybe you want... {$value=$settings.signature} and then {$settings.$value} ? if not, how would you do whatever you are asking in pure php and then maybe whe can translate it to smarty?
If you have used PHP variable variables it is like this $Hello = "World"; $a = "Hello"; $a; //Returns Hello $$a; //Returns World
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.