BoltCM

Sophisticated, Lightweight and Simple

Jump to docs navigation
Edit on GitHub

Note: You are currently reading the documentation for Bolt 3.0. Looking for the documentation for Bolt 3.2 instead?

Field types » Select field

Choose from Preset values:

A drop-down list to make a pre-defined selection from. This field has many options and many possibilities but is less complicated than it might seem at first glance.

Basic Configuration:

        somevalue:
            type: select
            values: [ none, foo, bar ]

Example usage in templates:

{{ record.somevalue }}

You can also get the values from the records of a particular ContentType.

        somevalue:
            type: select
            values: mycontenttype/fieldname

To display multiple values simply separate them with commas.

For example to display both the id and title of 'pages':

        somevalue:
            type: select
            values: pages/id,title

If you wish to store another field or value from the original ContentType in your database, use the keys setting. If you do this, it will not store the 'id', but the value of the field you specify. For example:

        somevalue:
            type: select
            values: persons/lastname
            keys: slug

If the list is growing longer, there are a few ways to make it more manageable:

        somevalue:
            type: select
            values: programme/name
            sort: name
            autocomplete: true
            limit: 1000

Finally you can pass filters to the query using the filter option. For a full reference of what can be passed to a where filter you can see the content fetching documentation.

In adition to filters on the ContentType values, you can use taxonomy conditions, as in the following example:

        somevalue:
            type: select
            values: pages/title
            filter: { categories: news }

You can then fetch the selected record by using the following code:

{% setcontent linkedpage = "pages" where { 'id': record.somevalue } returnsingle %}

Additional options:

Selecting multiple values

You can also allow the user to select multiple values by setting the options multiple to true like this:

        somevalues:
            type: select
            values: [ none, foo, bar ]
            multiple: true

If you set it to multiple you will also have some different ways to use it in the templates.

For example if you want to see if bar was one of the selected values:

{% if 'bar' in record.somevalues %}
    ..
{% endif %}

Or if you want to print out the selected values in an ul:

<ul>
    {% for values in record.somevalues %}
        <li>{{ values }}</li>
    {% endfor %}
</ul>

Or if you just want to print them out after one another separated by commas:

{{ record.somevalues|join(', ') }}

Defining values as a hash

The options in the list can be defined as either a 'map' or a 'hash'. If you use a list (like above), the options visible in the drop-down list will be the values stored in the database. If you want to store other values, you can use a so-called 'hash'.

In the following example, 'yes', 'no' and 'undecided' will be stored in the database:

        somevalue:
            type: select
            values: { 'yes': "Yes", 'no': "No", 'undecided': "Well, it can go either way" }

Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.
Spotted a typo, or have something to add? Edit this page on GitHub.