Forum

Thread tagged as: Question

How to have a list box in the CMS

Hi,

I would like to create a list box in Perch, in order to be able to select predefined lines of text from a .html template that are to be generated in a website as HTML code.

I found this:

https://docs.grabaperch.com/docs/templates/attributes/type/select/

but as they are comma separated values, I cannot use a comma.

Is there any way around this situation?

Thank you

Garth Holmes

Garth Holmes 1 points

  • 6 years ago

You could create a multiple item region to place the various lines of text in and use a dataselect instead?

https://docs.grabaperch.com/docs/templates/attributes/type/dataselect/

Simon Clay

Simon Clay 127 points

It would be great to be able to 'escape' commas in select and radio fieldtypes, but unfortunately it's not possible as yet. It would be a useful feature, I have had need of it in the past.

You could use individual checkboxes, as they have a value field which will take commas I believe:

<perch:content id="text_line_1" type="checkbox" label="Text Line 1" value="A checkbox can have a comma, I think" />
<perch:content id="text_line_2" type="checkbox" label="Text Line 2" value="Escaping commas would be a useful feature, I think" />
<perch:content id="text_line_3" type="checkbox" label="Text Line 3" value="Because commas are used in values, sometimes" />

However, this would allow the user to select more than one line of text which may not be what you intend.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would do this:

<perch:content id="textline" type="select" options="A,B,C" suppress="true" />

<perch:if id="textline" value="A">
    ... your text line ...
</perch:if>
<perch:if id="textline" value="B">
    ... your text line ...
</perch:if>
<perch:if id="textline" value="C">
    ... your text line ...
</perch:if>

Philip Gwynne said:

You could create a multiple item region to place the various lines of text in and use a dataselect instead?

https://docs.grabaperch.com/docs/templates/attributes/type/dataselect/

Hi Phillip,

You have helped me solve a problem in a very simple way, thank you.