We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Variable Concatenation in volt

How Can I concatenate variable in volt?

I want to create HTML option list using foreach and put that inside one variable and want to use that variable n number of time on same page



1.5k
edited Feb '15

try this

{{ [1, 2, 3]|join(' | ') }}

Output

1 | 2 | 3

Also try this

{{ 1 " join with " 2 " join with " 3}}

Output

1 join with 2 join with 3

Explanation

Join with " [anything you want to join with] "



43.9k
Accepted
answer

Hi,

I want to create HTML option list

do you mean within a volt view, you want to create a variable that contain a full html option list ?

with Phalcon\Tag they are many helpers for building forms:

{{ select("type", productTypes, 'using': ['id', 'name']) }}

Or better

//in controller
$productTypes = array(
            "N" => "Brand New",
            "G" => "Good conditions",
            "U" => "Used",
            "D" => "Unuseable"
        );
$this->view->setVar("producTypes", $productTypes);

// in view
{{ selectSatatic("status", productTypes }}