We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.4k
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 }}