Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenation in smarty

Tags:

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.

like image 590
user1163513 Avatar asked Apr 05 '12 05:04

user1163513


People also ask

What is an example of concatenation?

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.

What is concatenation in algorithm?

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.

What is the principle of concatenation?

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.

What is variable concatenation?

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.


2 Answers

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

like image 195
periklis Avatar answered Sep 21 '22 01:09

periklis


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 
like image 33
Bjoern Avatar answered Sep 20 '22 01:09

Bjoern