data-sly-repeat define max item via cq dialog

Avatar

Avatar

angelinek209805

Avatar

angelinek209805

angelinek209805

02-01-2019

I am trying to use data-sly-repeat and need to define the max item to repeat. I though I could use the following HTL but if i replace the number with properties from the dialog (maxItems - sling:resourceType="granite/ui/components/coral/foundation/form/numberfield"), the component breaks with error Cannot get DefaultSlingScript: Operands are not of the same type: comparison is supported for Number types only.

<sly data-sly-repeat="${reference.items @ begin = 0, end = properties.maxItems}">

Is there a simple way of using only HTL to achieve this? I also tried ${properties.maxItems @ context='number'} but no luck

Thanks in advance.

Replies

Avatar

Avatar

Gaurav-Behl

MVP

Avatar

Gaurav-Behl

MVP

Gaurav-Behl
MVP

03-01-2019

May be its not written to support type conversions and works only within the indices of the collection.

htl-spec/SPECIFICATION.md at master · adobe/htl-spec · GitHub

data-sly-repeat:

  • Iterates over the content of each item in the attribute value and displays the containing element as many times as items in the attribute value, allowing to control the iteration through the following options:
    • begin - iteration begins at the item located at the specified index; first item of the collection has index 0
    • step - iteration will only process every step items of the collection, starting with the first one
    • end - iteration ends at the item located at the specified index (inclusive)

Go with Ravi/Arun's approach.

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

04-01-2019

"Operands are not of the same type: comparison is supported for Number types only."

means not the same type.

Make sure that properties.maxItems is of type of number

Avatar

Avatar

angelinek209805

Avatar

angelinek209805

angelinek209805

04-01-2019

Thanks all for the insightful suggestions.

Will go with Java/JS method since unable to achieve with HTL although the properties.maxItems type was changed to Long.

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

16-01-2019