I want to assign the value obtained from the concatenation of these two variables with a string.
{assign var="url" value="{$WS_PATH}aircraft_images/{$images[i].image}"}
Please let me know how can we do this in smarty.
The concatenation of two or more numbers is the number formed by concatenating their numerals. For example, the concatenation of 1, 234, and 5678 is 12345678. The value of the result depends on the numeric base, which is typically understood from context.
In this algorithm we use the standard template library function We use the function named append to concatenate the input strings ie, s1. append(s2) append function directly appends two strings without using any extra string.
Concatenation (from Latin concatenare, to link together) is taking two or more separately located things and placing them side-by-side next to each other so that they can now be treated as one thing.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect.
One of these should work:
{assign var="url" value=$WS_PATH|cat:"aircraft_images/"|cat:$images[i].image}
Or
{assign var="url" value="`$WS_PATH`aircraft_images/`$images[i].image`"}
I am not sure if the $images[i].image will be parsed correctly, you may have to {assign} it to another variable first
You've used assign
properly.
A simplified example could look like this:
yourphpfile.php:
$tpl = new Smarty; $tpl->assign('var1','Hello'); $tpl->assign('var2','World'); $tpl->display('yourtemplate.tpl');
yourtemplate.tpl:
... <body> {assign var="url" value="{$var1} - and - {$var2}"} {$url} </body>
...will result to the output:
Hello - and - World
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With