templatesliferaystructureliferay-velocityweb-content

How to access selection box field of Structure in Template using vm?


I want to create a Liferay web content which will display selection box of multiple states.

I created one select field in Structure for showing States and gave multiple options such as- Punjab, Karnataka, Keral,....

Now I want to access these select field options in Template.

Can anyone please tell me how to access select field & its options in template?

Thanks in Advance :)


Solution

  • It sounds like you are trying to build portlet functions with web content, which is not what it was made for.

    Nevertheless: You can access the structure with

    #set($structureService = $serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalService"))
    #set($structure = $structureService.fetchDDMStructureByUuidAndGroupId("THE-UUID-OF-YOUR-STRUCTURE", $articleGroupId))
    

    The structure will contain the options for your field (see DDMStructure).

    But if you are really into the web content approach - I would move the configuration from the structure to the web content article:

    Create a repeatable text field in the structure and add your states in the article itself (form builder approach). Then you can simply configure a different set of options for every article. And you can use the options in the template:

    <select name="...">
      #foreach ($state in $yourStateFieldName.siblings) 
        <option value="$state">$state</option>
      #end
    </select>