Karsten
I'm new here

How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

Hello,

I want to sort the values (_list.value.name) behind the selected checkboxes but don't know how. Has anyone an idea? Thanks

FORM

<CMS_INPUT_CHECKBOX name="cs_location" gridWidth="3" hFill="yes" sortOrder="ascending" useLanguages="no">

    <CMS_INCLUDE_OPTIONS type="database">

      <LABELS>

        <LABEL lang="*">#item.name</LABEL>

      </LABELS>

      <TABLE>FSStoinside.news_locations</TABLE>

    </CMS_INCLUDE_OPTIONS>

    <LANGINFOS>

      <LANGINFO lang="*" label="Show ONLY news of following location/department (optional)"/>

      <LANGINFO lang="DE" label="NUR Nachrichten für folgenden Standort oder Abteilung anzeigen (optional)"/>

    </LANGINFOS>

  </CMS_INPUT_CHECKBOX>

HTML

$CMS_FOR(_list,cs_location)$

   <li>$CMS_VALUE(_list.value.name)$</li> 

$CMS_END_FOR$

Does not work!

$CMS_FOR(_list,cs_location.sort(x->x.value.name))$

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

cs_location (value type of CheckboxEditorValue) is a set and "sort" isn't supported for this datatype. You have to transform it to a list first. E.g. like this: [] + cs_location (i.e. adding all elements of the set to an empty list). The result than could be sorted: ([] + cs_location).sort(..)

tl;dr

Sort is only supported for lists.

Peter

View solution in original post

0 Kudos
6 Replies
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

Do you get any error? I suspect the list cs_location isn't modifyable. So doing a copy first could do the trick: cs_location.copy.sort(x->x.value.name)

Peter
0 Kudos
Karsten
I'm new here

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

No, that doesn't work either ...

0 Kudos
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

But the unsorted for-loop from your initial post is working? Please check your log and report back.

Peter
0 Kudos
Karsten
I'm new here

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

Unsorted loop works.

The Log

ERROR ($CMS_FOR( _list, cs_location.copy.sort(x -> x.value.name) )$ at 27, 1): Cannot iterate over: class de.espirit.firstspirit.parser.eval.Undefined

    inside of: Template 'Standard' (id=544431)

    inside of: $CMS_VALUE(#global.page.body("column_right"))$ - at 30, 7

    inside of: Template 'local news' (id=757642)

    inside of: $CMS_TRIM(level:3)$ - at 19, 1

    inside of: $CMS_FOR( _list, cs_location.copy.sort(x -> x.value.name) )$ - at 27, 1

0 Kudos
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

cs_location (value type of CheckboxEditorValue) is a set and "sort" isn't supported for this datatype. You have to transform it to a list first. E.g. like this: [] + cs_location (i.e. adding all elements of the set to an empty list). The result than could be sorted: ([] + cs_location).sort(..)

tl;dr

Sort is only supported for lists.

Peter
0 Kudos
Karsten
I'm new here

Re: How to sort <CMS_INCLUDE_OPTIONS type="database">

Jump to solution

That works out! Thank you very much!

$CMS_SET(_locationsSet,[]+cs_location)$

$CMS_FOR(_list,_locationsSet.sort(x->x.value.name))$

0 Kudos