0

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 :)

Saha
  • 23
  • 5
  • You are mixing things up: A structure defines the fields for a web content article. If you have a selection box in a structure, you define which values an _editor_ of an article may choose from. A template defines how _one article_ is transformed to HTML. Not a structure. Are you trying to rebuild the webcontent editor, or are you trying to configure a form with your webcontent article (some kind of formbuilder)? – Tobias Liefke Dec 14 '15 at 10:40
  • Thanks for the reply :) ..Actually I want to show a select box with multiple values using web-content. Since, as per the requirement, all the values should be dynamic so I have to create a web-content using Structure & Template. And based on the selected value, dynamic values will be shown in another drop-down//selection box. In other words, I want to achieve dynamic selection using web-content. – Saha Dec 14 '15 at 10:53
  • So, for this, I added one "selection-list" field with some options (passed values to "label" & "values") in Structure. And in Template I am trying to access these options. – Saha Dec 14 '15 at 11:02

2 Answers2

0

Is reading the selected value what you're asking?

For field of type select with name selectionField, just call getData() to read the selected value (as string).

$selectionField.getData()
Tomas Pinos
  • 2,812
  • 14
  • 22
  • I am talking about the complete code ( i.e, how can we access select field in template, how to display all its options using template, then based on user selection of options, showing options in some other selection field). For ex: in normal HTML we write the following code: ` ` The same thing I want to achieve through velocity in template. – Saha Dec 14 '15 at 11:54
  • And then based on the car model that user selected (for example, he selected Mercedes), other select box will show its "price, fuel, etc.". – Saha Dec 14 '15 at 12:03
  • It seems to be a bad idea to implement such use case with journal articles and structures. Do yourself a favor and create a portlet. – Tomas Pinos Dec 15 '15 at 07:38
  • It's a client's requirement to use journal articles and structures. They don't want portlet for this. – Saha Dec 28 '15 at 05:11
0

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>
Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58