Poll Component Developer Guide - Rendering

Rendering the Poll

Available Poll Data

To implement a rendering template (JSP or Freemarker) for the poll component, you need to understand the data available for rendering. The following table lists the fields exposed to your template:

FieldDescription
pollDocumentThe root-level HST bean representing the processed poll document. For plugin-supplied poll documents, this bean is implemented by org.onehippo.forge.poll.contentbean.PollDocument. If no poll document is present, this field is null. In that case, do not render the poll. Custom poll documents may include additional properties, but the plugin-supplied type exposes only the poll field:
pollDocument.pollThe HST bean representing the poll compound, implemented by org.onehippo.forge.poll.contentbean.compound.Poll.
pollDocument.poll.textA string containing the value of the text attribute of the poll compound.
pollDocument.poll.introductionA string containing the value of the introduction attribute of the poll compound.
pollDocument.poll.optionsA list of HST beans representing the available options for this poll. Each option is implemented by org.onehippo.forge.poll.contentbean.compound.Option.
pollDocument.poll.options[].valueA string containing the value attribute of the option.
pollDocument.poll.options[].labelA string containing the label attribute of the option.
voteSuccessA boolean indicating whether a voting attempt was successful. This field is only available if a voting attempt was made.
optionA string containing the option that was previously voted on. This field may not always be present.
pollVotesA Java bean of type org.onehippo.forge.poll.bean.PollVotesBean containing vote data for the pollDocument. This bean exposes votes data as options:
pollVotes.optionsA list of beans representing the poll options.
pollVotes.options[].valueSame as pollDocument.poll.options[].value.
pollVotes.options[].labelSame as pollDocument.poll.options[].label.
pollVotes.options[].votesCountA long integer indicating the number of votes for this option.
pollVotes.options[].votesPercentageA long integer representing the rounded percentage of votes for this option relative to the total votes for the document.

Creating a Template

Render the poll component using a JSP or Freemarker template. The poll plugin provides a sample Freemarker template that demonstrates how to render the poll attributes. You can find this template in the repository at:

hst:[your_project]/hst:configurations/hst:default/hst:templates/poll.component.ftl@hst:script

To customize the rendering, modify this template as needed and ensure it is included in your site.war deployment.

If you create a custom template, register it under /hst:[your_project]/hst:configurations/[your_project]/hst:templates and set the component's hst:renderpath property to reference your template.

Console showing poll.component.ftl template in HST configuration

If you use the default Freemarker template provided by the poll plugin, the template poll.component.ftl is available for your component.

Share Feedback
Page: /build/plugins/poll/rendering
Section: Build
Category *