craft helper
1.0.0
我經常在項目上使用的工藝CMS宏和組件的集合。隨意使用,更改和擴展。歡迎建議。
我通常將宏包含在第一個級模板中,例如_router.html ,我從其中委派所有頁面並將macros設置為參數,包括:
{# _router.html or another first level template #}
{% set macros = ' partials/_/_macros.html ' %}
{% set notfound = ' 404 ' %}
{% include [ ' pages/ ' ~ entry . type . handle , notfound ] with { macros : macros } %}在頁面模板中,我只是導入宏並將其繼承到組件:
{# page.html #}
{% import macros as helper %}
{# Macro: macros/include.twig #}
{{helper. include ( ' modules ' , ' hero ' , {
image : entry . image . one () ?? null ,
macros : macros
})}} _macros.html或.twig:
{% macro myMacro( param ) %}
{# Do something here #}
{% endmacro %}ita麻省理工學院!