PDA

View Full Version : Set Mixed Variables In Template


BulliM
11-03-2017, 12:22 PM
I need help to understand how template variables works.

I need a variable from table phrase in database. Name of the variable key is a mix between plaintext and variable. Cannot explain exactly what I mean, so I show an example:

{vb:phrase 'pre_'.$var['key'].'_post'}

The reason why I search for: I need the variable 'text' from db.phrase where varname = myphrasename within a part of myphrasename ($var['key']) is variable. Hope you understand my problem.

Solved. That works:

{vb:phrase prefix_$conversation['prefixid']_title_rich}

noypiscripter
11-03-2017, 08:36 PM
I know it's solved and I was actually surprised your solution works. But I would do it this way using string concatenation:

{vb:set phraseVar, 'prefix_'}
{vb:strcat phraseVar, {vb:raw conversation.prefixid}}
{vb:strcat phraseVar, '_title_rich'}
{vb:phrase {vb:raw phraseVar}}

BulliM
11-04-2017, 07:08 AM
I know it's solved and I was actually surprised your solution works.
Me too!

But I would do it this way using string concatenation:

{vb:set phraseVar, 'prefix_'}
{vb:strcat phraseVar, {vb:raw conversation.prefixid}}
{vb:strcat phraseVar, '_title_rich'}
{vb:phrase {vb:raw phraseVar}}


I'll try. Thank you!

EDIT: Works! THX!