Code Snippets Twig

Short texts Twig 🧑‍💻 Code snippets Twig ✍️ Reading lists Twig 👀

wp-timber

« {% for page in posts.pagination.pages %} {% if page.link %} {{page.title}} {% else %} {{page.title}} {% endif %} {% endfor %} »

collapseproblem.twig

{{ title }} {{ columnNameOne }} {{ columnNameTwo }} {% for card in cards %} + − {{ card.title }} {{ card.columnNameOne }} {{ card.columnNameTwo }} {% for element in card.element %} {{ element[‘title’] }} {{ element[‘columnNameOne’] }} {{ element[‘columnNameTwo’] }} {% endfor %} {% endfor %} + − Modules and packages 3 lectures 29:10 […]

#CraftCMS: Eager-Load Nested Sets of Elements

{# According to docs (https://craftcms.com/docs/templating/eager-loading-elements), this is how you Eager-Load Nested Sets of Elements #} {% set entries = craft.entries({ section: ‘news’, with: [ ‘entriesField.assetsField’ ] }) %} {# And this is how you Eager-Load Elements Related to Matrix Blocks #} {% set blocks = entry.matrixField.find({ with: [‘blockType:assetsField’] }) %} {# or #} {% set […]

Menu tpl that shows menu level (Drupal 8)

{% import _self as menus %} {# We call a macro which calls itself to render the full tree. @see http://twig.sensiolabs.org/doc/tags/macro.html #} {{ menus.menu_links(items, attributes, 0) }} {% macro menu_links(items, attributes, menu_level) %} {% import _self as menus %} {% if items %} {% if menu_level == 0 %} {% else %} {% endif %} […]