Skip to content

Select Field

A dropdown. What matters here is where the options come from — there are two modes.

Static list

Options are typed in by hand, a caption and a value per row:

CaptionValue
Catcat
Dogdog

The caption is what the editor sees, the value is what gets saved. Right for a short list that does not change: sizes, statuses, a couple of layout variants.

From a model

Options are read from the database. You pick the model, the field to display, the field to save, and optionally a filter, a sort order and a limit.

Right when the list is data rather than a constant — cities, categories, brands. Add a row to the table and it shows up in the dropdown by itself, with nothing to edit in the constructor.

Multiple

Multiple turns the dropdown into a multi-select. The value then holds several entries instead of one.

Output:

html
<span class="badge">{$status}</span>

Caption and value are different things, and confusing them is expensive

The editor sees the caption; the database stores the value. The value is also what your template compares against:

CaptionValue
In stockin_stock
html
{if $status == 'in_stock'}

It is tempting to put the same words in both — "In stock" as the value too. Six months later the client asks for "Available now", and it turns out the wording is not the only thing to change: every saved row holds the old phrase and the template compares against it. Both have to be fixed, and no page may be missed.

With a separate key there is no such edit: change the caption, and the site shows new wording while the database and the template stay as they were.

© PageBlocks 2019-present