0

well, i assign this array (this array is for language) to tpl:

$arrayLang = array (
    "id" => "ID",
    "name" => "Nombre",
    "active" => "Activo"
);
$tpl->assign('LANG' => $arrayLang);

and i assign other array from a query to the database, this query fetch an array similar to:

$arrayQuery = array (
    0 => "id",
    1 => "name",
    2 => "active"
);

$tpl->assign('DATA' => $arrayQuery);

and i need to print the value from $arrayLang by key (this from $arrayQuery), so i use a loop:

<ul>
    {loop name="$DATA"}
        <li>{$LANG.$value}</li>
    {/loop}
</ul>

but this code print empty, i have tried with {$LANG[$value]} for same result. So, how can i do it?

Thanks in advance.

2 Answers 2

0

You should do it in PHP while not in TPL. RainTpl didn't support this kind of call: {$LANG.$value}.

$arrayQuery = array (
    0 => "id",
    1 => "name",
    2 => "active"
);
foreach($arrayQuery as $key=>$val) $arrayQuery[$key] = $arrayLang[$val];
$tpl->assign('DATA' => $arrayQuery);
Sign up to request clarification or add additional context in comments.

1 Comment

i have made this function: function key2val($key, $array) { if (isset($array[$key])) { echo $array[$key]; } else { echo $key; } } and the use in tpl {function="ket2val($value, $LANG)"} ... for futures searchers
0

First, wiki of raintpl here: https://github.com/rainphp/raintpl3/wiki/Documentation-for-web-designers

Secondly, use loop: {loop="$var"} $key and $value

The problem probably is bad loop.

Try change the loop.

Best regards!

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.