Craft CMS & Twig Snippets
Some samples dumped here
Related Entries (aka “entries” type field)
{% set authors = craft.entries.section('newsAuthors').relatedTo(entry) %} {% set auth = authors.first() %}
Current Page URL
{{ url(craft.request.path) }}
How to get NEO/ Matrix Field in template
{{entry.textWithSubtitle.first().subtitle}}
Loop entire section
{% for key,job in craft.entries.section('jobs') %} OUT {% endfor %}
Neo/Matrix fields with block types
{%for key2,block in job.textWithSubtitle%} {% if block.type == "textwithsubtitle" %} {{ block.subtitle }} {{ block.body }} {% elseif block.type == "text" %} {{ block.text|markdown }} {% endif %} {% endfor %}
Useful string filters
{{block.body|striptags }} - strip html tags {{block.body|striptags|e }} or {{block.body|striptags|escape }} - escape special chars aka &->&
Get URL segments
{{craft.request.getSegment(1)}}
Posted on October 18, 2016 at 16:00 by arte · Permalink
In: Craft CMS + Twig, English, Fighting the system
In: Craft CMS + Twig, English, Fighting the system