Select, Mutli-Select and Tags

Select and Multi-Select are special purpose content tags. They’re used for choice fields on pages, but they also can be used to group pages with the same select values. This is useful for tagging and other complex taxonomies.

Adding a select to a page

To add a single select to a page use the following tag structure. This is like other page tags, where the name comes first, and then the options.:

Examples:

{% page "category" type="select" %}
{% page "tags" type="select" multiple="true" %}

Getting Data about a select

The {% select %} template tag will get data about tags in use:

{% select "tags" %}
<ul>
{% for tag in tags %}
    <li>{{ tag.record }}
{% endfor %}
</ul>

For a site about electronics that might render:

<ul>
    <li>Arduino
    <li>Power Supplies
    <li>LCD Display

Getting Pages that match a select

The select_page template tag is used to get pages that match a particular record. Continuing on the electronics theme, here’s an example:

{% select_page "tags" "LCD Display" %}
<ul>
{% for selected_page in pages %} {# don't reuse the variable `page`, it's bad form #}
    <li>{{ selected_page.content.title }}
{% endfor %}

That might render:

<ul>
    <li>22" IPS Display
    <li>7" TFT Raspberry Pi Display
    <li>TFT versus IPS Technology

It’s possible to combine select with select_pages to do complex listings. I really like examples.:

{% select "tags" %}
<ul> <!-- top level list -->
{% for t in tags %}
   <li> {{ t.record }}
   {% select_pages "tags" t.record %}
   <ul> <!-- nested {{ t.record }} list -->
        {% for selected_page in pages %}
        <li>{{ selected_page.content.title }}
        {% endfor %}
   </ul>
{% endfor %}

That might render:

<ul><!-- top level list -->
    <li>Arduino
    <ul><!-- nested Arduino list -->
        <li>Arduino Nano is back in Stock!
        <li>Adafruit has new wifi Arduino-compatible board
    <li>Power Supplies
    <ul><!-- nested Power Supplies list -->
    <li>LCD Display
    <ul><!-- nested LCD Display list -->
        <li>22" IPS Display
        <li>7" TFT Raspberry Pi Display
        <li>TFT versus IPS Technology