Skip to content

Instantly share code, notes, and snippets.

@atroutt
Created November 16, 2012 21:54
Show Gist options
  • Save atroutt/4091250 to your computer and use it in GitHub Desktop.
Save atroutt/4091250 to your computer and use it in GitHub Desktop.
Liferay velocity templates and structures for displaying all articles with a given structure.
## name: All transition questions
## description:
## This is the template to display all transition questions. The structure that is associated with this template directly is not really used.
## Instead it depends on the TransitionQuestion template and TransitionQuestion structure.
## The $structureId, below needs to be updated with the id of the TransitionQuestion structure in your instance of Liferay.
#* update your portal-ext.properties to add these two lines:
#allow velocity templates to use the serviceLocator variable
journal.template.velocity.restricted.variables=
*#
## --------------------------------------------
## Setting utility classes.
##
#set ($journalArticleService = $serviceLocator.findService('com.liferay.portlet.journal.service.JournalArticleLocalService'))
#set ($journalContentUtil = $utilLocator.findUtil('com.liferay.portlet.journalcontent.util.JournalContent'))
##
## Setting handy variables
##
#set ($groupId = $getterUtil.getLong($groupId))
#set ($languageId = $languageUtil.getLanguageId($locale))
#set ($structureId = "372144")
## Get all of the articles
#set ($obcClass = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleCreateDateComparator"))
#set ($booleanType = $portal.getClass().forName('java.lang.Boolean'))
#set ($obcConstructor = $obcClass.getConstructor($booleanType.getField('TYPE').staticValue))
#set ($obc = $obcConstructor.newInstance(false))
#set ($articleHits = $journalArticleService.getStructureArticles($groupId, $structureId, -1, -1, $obc))
##
## Here's the visible part:
##
<p><span style="font-size: larger; ">Here are some questions that we have received and the answers:</span></p>
<p><style type="text/css"> .responses, .responses th, .responses td { border: 1px solid black; padding:4px; font-size: larger;} .responses th {text-align: center;} .responses tr > td:first-child + td {font-weight:bold; color:green; } </style></p>
<table style="border-collapse:collapse" class="responses">
<colgroup> <col /> <col style="font-weight:bold; color:green;" /> </colgroup>
<tbody>
<tr>
<th>QUESTION</th>
<th>ANSWER</th>
</tr>
#foreach ($doc in $articleHits)
#set ($articleId = $doc.articleId)
#set ($articleDisplay = $journalContentUtil.getDisplay($groupId, $articleId, null, null, $languageId, null, 1, $xmlRequest))
$articleDisplay.content
#end
</tbody>
</table>
<root>
<dynamic-element name='nothing' type='text' repeatable='false'></dynamic-element>
</root>
## name: Transition question
## description:
## This is the template for a single question. It's not intended to be displayed by itself, but rather as a row in the allQuestions template.
<tr>
<td><strong>${Topic.getData()}</strong>: &quot;${Question.getData()}&quot;</td>
<td>${Answer.getData()}</td>
</tr>
<root>
<dynamic-element name='Topic' type='text' repeatable='false'></dynamic-element>
<dynamic-element name='Question' type='text_box' repeatable='false'></dynamic-element>
<dynamic-element name='Answer' type='text_box' repeatable='false'></dynamic-element>
</root>
@atroutt
Copy link
Author

atroutt commented Nov 20, 2012

These are structures and templates for use in Liferay.
They were created to work with Liferay CE 5.2.3

If you create one or more web content items with the "Transition question" structure and template you can display them all in a simple table by creating one web content item and giving it the "All transition questions" structure and template. The idea was that this way business users could update tables of questions and answers without having to touch html.

NOTE: To use these templates you will need to update your portal-ext.properties to add these two lines:
#allow velocity templates to use the serviceLocator variable
journal.template.velocity.restricted.variables=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment