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

Can we use variable variables in volt?

As title said, I want to use variable variables in volt...

We can do that easy with raw php template:

$a = 'hello';
$$a = 'world';
echo "$a ${$a}";

Can we do this in volt?

{% set account = "user_"~item~"_account" %}

and use this variable like this:

{{ {{account}} }}


98.9k

Sorry, but such syntax is not supported by Volt, since you can also embed php code in volt templates, you can use:

{% set account = "user_"~item~"_account" %}
<?php echo $$account; ?>

@Phalcon you are right.... Do you think is that necessary to be implemented in volt?



98.9k

Well, Volt (as Jinja) is intended to provide a simple syntax to help designers to create templates and this functionality is not clear so I think that's the reason because Jinja doesn't implement it too