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 %}ITSA MIT!