New answers tagged

1

As you noted in your comment, the Twig Perversion plugin will do exactly what you need. It allows you to return a value from a macro, which isn't typically something that Twig permits. Personally, I'd consider it to be fairly safe to rely on this plugin for a few reasons. Marion is a long-standing and trusted developer in the community, the plugin is ...


2

Entry templates are assigned on a per-section basis, and each section can only have a single entry template per site. The workaround is to create a "proxy" template and use that as your section's entry template. The only responsibility for the proxy template is to {% include %} another template (the actual entry template), based on some conditions. ...


1

Try inside this in the main template file: {% block access %} {% requireLogin %} {% endblock %}


1

I figured out that the best way to do this was to replace the newline character \n. Final code: {{ plainText|replace({ "\n" : ", "}) }}


2

Marion's answer beat me to this while I was writing but it's essentially very similar. Replace raw with, say, upper and you'll be able to visually see what's going on: // {{ entry.maxWidth|length ? 'max-width: '|raw ~ entry.maxWidth ~ 'px;'|raw : 'max-width: unset;'|raw }} MAX-WIDTH: 160PX; // {{ entry.maxWidth|length ? 'max-width: ' ~ entry.maxWidth ~ 'px;'...


3

You are asking about Twig's operator precedence: The operator precedence is as follows, with the lowest-precedence operators listed first: ?: (ternary operator), b-and, b-xor, b-or, or, and, ==, !=, <=>, <, >, >=, <=, in, matches, starts with, ends with, .., +, -, ~, *, /, //, %, is (tests), **, ??, | (filters), [], and .: | is higher ...


2

How about doing something like this? {% set style = entry.maxWidth|length ? entry.maxWidth ~ 'px' : 'unset' %} {{ style|raw }}


1

Having done some further testing and research I believe this is a case of having to merge two date objects and ensuring that these are set as date/time objects when merging them into a variable. Here are some examples way: {% set thisWeeksDayAndTime = thisWeeksDay|date() ~ ' ' ~ classStartTime|time() %} {% set thisWeeksDay = page.startDate|date_modify('...


2

You're looking for the filter filter: https://docs.craftcms.com/v3/dev/filters.html#filter Specifically something like this (untested): {% set activeChildren = children|filter(child => child.associatedTerm|length) %} {% set inactiveChildren = children|filter(child => child.associatedTerm|length == 0) %} You now have two unique arrays to do with as you ...


Top 50 recent answers are included