Forum

Thread tagged as: Question

Page Attributes and Collections

Is it possible in Runway to have a page attribute where the options available to the content editor are selected from a collection?

The scenario is that I would like editors to be able to create a collection of themes with items such as page colour, banner image, banner size, etc and give the theme a meaningfull name. When creating a page they could then select a single theme name as a page attribute.

Creating the collection is fine but I'm struggling with how to get the collection into the attributes template.

Kevin Jackson

Kevin Jackson 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I've not tried it, but you might be able to do this with <perch:related>

https://docs.grabaperch.com/runway/relationships/

Drew Thanks, I have some progress. I have an attributes template with the follwing contents:

<perch:pages 
    <perch:related id="theme" collection="Page Themes" required="true" label="Theme for Page" help="Add a single theme only.">
        <perch:content id="themeSlug" />
    </perch:related> 
/>

This produces a "multi-select" type field in Admin Page Details but I've not been able to make it a "select" or "radio" field type which would be much more appropriate. It is workable but just not very elegant from the user perspective.

multi-select

The value stored in the page's pageAttributes array is the collection's itemID so easy enough to work with.

Any suggestions?

Thanks again. Kevin

Duncan Revell

Duncan Revell 78 points
Registered Developer

You can add max="1" to your perch:related tag which will only allow one selection to be made.

Duncan

Excellent, thank you. I never realised that was there.

I can see quite a lot of uses for this.

Now if only there was some way to specify a default value :-)

Kevin

Duncan Revell

Duncan Revell 78 points
Registered Developer

Try using the default="item_id" tag and see if that works. Substitute the actual id of "Theme Three" (or whichever one should be the default) for item_id.

it might work.