Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig include variable path name with concatenation

Tags:

php

twig

How do I specify an include to a view path that is a "concatenation". A simple example;

In form.twig;

{% include {path: 'survey.'group]} %}

group is a variable, that is passed in to the view from the controller. The view I am trying to load here is views/survey/example.twig

like image 588
mikelovelyuk Avatar asked Jul 03 '26 22:07

mikelovelyuk


1 Answers

The twig concatenation operator is ~.

So you should have have something like

 {% include 'survey/' ~ group ~ '.html.twig' %}

(or however exactly your concatenation needs to go).

like image 162
jbafford Avatar answered Jul 06 '26 12:07

jbafford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!