5

I want to concatenate an already assigned variable and save it to a new variable, something like this:

{assign var=permCat value="de.admin"}
{assign var=objectName value="myClass"}
{assign var=objectNameUpper value=$objectName|ucfirst}
{assign var=editPerm value=$permCat|cat:"canEdit"|cat:$objectNameUpper}

So, the resulting $editPerm should be: de.admin.canEditMyClass

How can I do this? Currently, it throws an error: Cannot use string as array offset...

1
  • On which of the four lines the error is thrown? Commented Feb 19, 2012 at 17:46

1 Answer 1

12

The error you describe cannot be caused by the given code. I assume you are trying to build a string "de.admin.canEditMyClass" to use as a variable {$builtString.foo}. That's where the error occurs, because smarty does not magically convert your string to a variable reference.

If you're using Smarty2:

{assign var=objectName value="myClass"}
{assign var=objectNameUpper value=$objectName|ucfirst}
{assign var=editPerm value="canEdit"|cat:$objectNameUpper}
{$de.admin.$editPerm.foo}

If you're using Smarty3:

{$de.admin.{"canEdit"|cat:{"myClass"|ucfirst}}.foo}
Sign up to request clarification or add additional context in comments.

Comments

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.