Add a limitation in repeatable dynamic-element in Liferay structure

1k views Asked by At

I create a structure and template in Liferay 6.2 and I want to add a limitation in number of repetition.

The attribute "repeatable" can have only "true" or "false" value.

The structure :

<root>
  <dynamic-element index-type="text" name="names" repeatable="true" type="text">
    <dynamic-element index-type="" name="" repeatable="false" type="text"> </dynamic-element>
  </dynamic-element>
</root>

The Template

#foreach ($communityname IN $names.getSiblings())
       $communityname.getData()  

 #end

</div>
1

There are 1 answers

0
tomic On

Unfortunately Liferay as default is not giving option to limit repeatable fields in structures (Yea I was suprised too). So either you have to accept them or just create some fields giving them suffix and then iterate over them by one of the ways:

If you make sure they are all in kind of container for example structure field parent has child1, child2, child3 and nothing else you can just use:

#foreach ($communityname IN $namesParent.getChildren())
       $communityname.getData()  
#end

If in parent field there are also other field than just these you want to iterate, I sugest to use range and iterate over childs using it in loop

#set($range = [1..5])