symfony - Twig and atomic pattern — Clean twig rendering -


i'm trying follow atomic design pattern twig.

when rendering simple atom, need like:

{% include '@mybundle/resources/views/atoms/button/button.html.twig' { href: '/section1', text: 'example text' } %} 

this approach starts getting messy when atom or component has more variables, or directory structure bit more complex.

i'd awesome able like:

{% button('/section1','example text') %} 

i know can achieved twig function, i'm worried pattern can tricky larger code base.

any experience around this? cheers!

you can use macro structure. read documentation: http://twig.sensiolabs.org/doc/tags/macro.html

{% macro button(href, text) %}     {% here can place template %} {% endmacro %} 

then need import twig file macro once. after can use construction {% button('/section1','example text') %}.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -