Code selects

node79 edited this page Aug 16, 2010 · 5 revisions

Tell us your code select stories: Matt Rolf asks “Who out there has used code select and what are you using it for? How do you like it? Share your stories!”

Code selects can be used for building simple lists, like 5,10,15,20,…,100 or letters from A-Z:

my %values;
for ('A'..'Z') {
    $values{$_} = "The letter $_";
return \%values;

Keys and values are mapped to option values and labels, so the above code will generate HTML like this:

<option value="A">The letter A</option>
<option value="B">The letter B</option>
<option value="C">The letter C</option>

Starting with Bricolage 1.10.4, a code select can access itself (as a Bric::Biz::Element::Field object) with the $field variable. This feature was originally added so the code select could access its story element:

# this is the code select field object

# this is the containing story instance or subelement

I think Bret has mentioned this before on the list, but Sportsnet’s
bricolage installation uses code selects extensively, mostly with the
“story-aware code select” patch that went into 1.10.4.

For example, a code select will detect the story’s category (hockey,
baseball, basketball, etc.) and then show a list of teams for that
sport. This way, a single “team associator” code select element can be
used, rather than having separate elements for each sport and relying
on the web team to pick the right element to add.

In a more complicated use, we also use a code select that displays a
list of stories in the same category (using Story::list()) to allow
stories to be inserted and shuffled around a “top stories” listing.
Same deal goes with the code select knowing what category to look in.

— Bric.PhillipSmith – 09 Jul 2008

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.