Commenting Your Twig Templates
You want to be a good dev and comment up all your code.
You want to be a good dev and comment up all your code.
You want to create a nav but don’t want to start at the top level. Using the following example section structure, show 2 levels deep inside of Software A (everything that is starred):
Software A
Item 1 **
Item x **
Item y **
Item z **
Item 2 **
Item 3 **
Software B
Item 1
Item 2
etc...
Software C
You want to add an ordinal suffix to a date (“st”, “rd”, “nd”, or “th”).
You want to do something like this ExpressionEngine statement, using Twig:
{switch="<tr>|||"}
You want to display x entries on the homepage. 0...x
of these entries may have been specified by the site author, using an Entries field. Those projects must come first, and the remaining n
slots must be filled with the most recent entries, no duplicates allowed.
You want to determine the number of selected items in a multi-select field.
You want to display the current “section” name in your template.
You want to retrieve only those entries with a lightswitch field set to “Yes”.
You want to add a file extension to all of your Craft URLs.
You want to store your Craft templates somewhere other than the default /craft/templates
directory.