Content template
From VYRE
Content Templates are basically JSP files for displaying and/or editing information about a single content item using the Item edit using template portlet. Unify provides a powerful JSP tag library to help quickly build custom form layouts to edit all aspects of data or file items (content and metadata attributes, item and user links, taxonomy, etc.).
[edit] Overview
The content templates have many advantages, but require basic HTML/JSP knowledge. Some of the advantages are:
- Fully customizable: The user has full control over the HTML surrounding the fields, and can use any JSP syntax available, for example to display fields based on workflow.
- Easy maintenance: The user can move fields around much quicker, and insert fields in between other fields without having to explicitly move all other fields down.
- Reusable: The content templates allow reference to attributes and links by name (rather than just ID), and can therefore be reused across stores and even across different installations.
The content templates also provide a new and much more user friendly way of linking to items and users.
To view/edit content templates, click the "Content Templates" node under the "Publishing" module, Found as a subfolder of the folder "files". Following is a brief description of the JSP tags available in the item content templates.
[edit] The Unify "VYRE Item" tag library
[edit] vyre-item:attribute
The following attributes can be used in this tag (one of id, externalId, name HAS to be specified):
- id - the ID of the attribute
- externalId - the external ID of the attribute (from an attribute template)
- name - the case-insensitive name of the attribute
- id
- name
- description
- keywords
- locale
- mode: [field/element] this is the input mode. If "field" is specified, then an input form field will be displayed. If "element" is specified, then (on submit) the value will be retrieved using innerHTML (or value if the element name is "input") from an HTML element (elementId attribute needs to be specified for this to work).
- hidden: [true/false] For mode="field". Specifies whether the input field should be hidden. Defaults to false.
- label: For mode="field". If this is set to "none", then no label is printed.
- elementId: For mode="element". The ID of the HTML element from which the value will be retrieved.
- defaultValue: A default value for the attribute. If not specified the default value specified in the attribute definition will be used.
- override: [true/false] If this is "true", then the existing attribute value will be overridden by the default value.
- presentationRuleId: The ID of the presentation rule to use for this attribute, if omitted the default presentation rule will be used. Works for custom attributes, and the name, description, and keywords. (since 4.3)
- presentationRuleName: The case-insensitive name of the presentation rule to use for this attribute, if omitted the default presentation rule will be used. Works for custom attributes, and the name, description, and keywords. Note that presentationRuleId overrides any value in this attribute. (since 4.3)
If you want to access the url parameters for the content template and put the value in an element, you can access the param object through the content template for example passing in test via url ( http://joe/item123?&test=1) can be accessed via ${param.test}. You can set the attribute to immediately pick up the url value by using <vyre-item:attribute name="name" mode="field" defaultValue="${param.test}"/>
[edit] vyre-item:attribute-value
The following attributes can be used in this tag (one of id, externalId, name HAS to be specified):
- id - the ID of the attribute
- externalId - the external ID of the attribute (from an attribute template)
- name - the case-insensitive name of the attribute. The following standard names are recognized:
- id
- name
- description
- keywords
- locale
- creation-date
- creator-name
- modification-date
- modifier-name
- defaultValue - the default value, if not specified the default value specified in the attribute definition will be used
- override - [true/false] specifies whether to override the existing value with the default value
- pattern - the date pattern to use for formatting creation date and last modified date
- var - an optional variable name, if specified then the attribute will be stored in the variable with this name, and will not be printed out
[edit] vyre-item:primary-attribute
Works exactly like the attribute-value tag except it displays data from the primary item for secondary localized items. You must be editing the item using the edit link provided provided in the XML output of both lists and items.
[edit] vyre-item:upload-field
Only for file store items. The following attributes can be used in this tag:
- required: [true/false] specifies whether a file must be uploaded or not. Note that this only applies when editing an existing item. When creating a new file store item, a file is ALWAYS required.
- type:[content/custom_thumbnail/custom_preview/service], default="content", if "service" then serviceId has to be set. *BUG if type="content" is used the file will not upload. To use the content upload type just do not include the type tag*
- serviceId: the custom service Id that the file will be uploaded into. That custom service should not be run automatically.
[edit] vyre-item:action
The following attributes can be used in this tag:
- type: Specifies the action to be performed. This can be one of the following:
- create
- createAndCheckin
- createAndActivate
- update
- checkout
- checkin
- discard
- delete
- activate
- deactivate
- requestTranslation
- checkoutUpdateAndCheckin (since 4.3.1.8)
- alertWarning:[true/false] (since 4.3.1.8): Optional. Whether or not an alert should be displayed when trying to do an action which cannot be processed (e.g. trying to checkout when creating an item)
Note that this tag prints a javascript method call, so if you are using it inside an a href, then remember to use the "javascript:" prefix.
Also note that all of the above are never applicable at the same time. If an action is not applicable for the current item state (for example "delete" when creating a new item), then an alert message will be displayed when the action is triggered. Therefore you will need to check whether the item variable is null when deciding whether to display an action or not. The default content template has an example illustrating this.
For a more detailed description have a look at the Item workflow page.
[edit] vyre-item:taxonomy
The following attributes can be used in this tag:
- sorting: Specifies how the categories in the tree are sorted. Can have one of the following values:
- none
- alphabetic_asc
- alphabetic_desc
- hideRestricted: [true/false] Specifies whether to hide categories that the current user does not have edit access to. Defaults to "false".
- preselectedIds: A comma separated list of IDs of categories that should be preselected.
- preselectedPaths: A comma separated list of full paths (/paths/like/this) to categories that should be preselected.
- rootIds: A comma separated list of IDs of categories that should be displayed at the first level in the tree.
- rootPaths: A comma separated list of full paths (/paths/like/this) to categories that should be displayed
- localizeLabels: [true/false] Specifies whether to localize category names or not for the branches label. If localized key is not found the category name is used. Defaults to "false".
- hidden: [true/false] (4.3.1.7) Specifies whether not to render the taxonomy tree. Defaults to "false".
[edit] vyre-item:item-link
The following attributes can be used in this tag (one of id, name HAS to be specified):
- id - The ID of the link definition.
- name - The name of the link definition (that is, the name of the other end of the link definition).
- mode - [field/formatted] The editing mode. If set to "field", then the old drop-down list will be displayed. If set to "formatted", then XSL will be used to transform the list (and xslId or xslName MUST be specified).
- xslId - Only for mode="formatted". The ID of the XSL stylesheet to use (this must be an item list stylesheet).
- xslName - Only for mode="formatted". The name of the XSL stylesheet to use (this must be an item list stylesheet).
- lightweight - [true/false] Only for mode="formatted". If false, then the full content and metadata of the linked items will be loaded. Defaults to "true".
- elementId - Only for mode="formatted". The ID of the HTML element that contains the link list.
- cardinality - [one/many] Only for mode="field". Can be either "one" or "many", default is "one". Determines whether to display a multiple select box or not.
- saveType - Only for mode="field". Specifies how to save the links. Either "replace_existing" (default) or "add_to_existing".
- inputType - [select/detect] Only for mode="field". Specifies how to get the link values. Defaults to "select". When "detect" is specified, then the link field will be hidden and the IDs of the items to link to will be retrieved from a request parameter by the name of "link_${linkDefinitionId}".
- firstOptionEmpty - [true/false] Only for mode="field", inputType="select", cardinality="one". Specifies whether the first option in the select list should be an empty option (default is true).
- savedSearchId - Only for mode="field". ID of a saved search to filter the options (optional).
- savedSearchName - Only for mode="field". Name of a saved search to filter the options (optional).
- locale - Only for mode="field" and inputType="select" ; use this attribute to filter items in a specific locale. The possible values are: a Locale ID String ('en', 'en_US', etc.), or 'user_locale' (displays items in the same locale as the currently logged-in user) or 'site_locale' (displays items in the same locale as the site the user is currently browsing).
- loadVersionHistory - Only for mode="formatted". [true/false] if true the version history of the item will be returned. The default value is false. (since 4.3.1)
- loadVersionContent - Only for mode="formatted". [true/false] if true the content and metadata of the versions of the item will be returned. The default value is false. (since 4.3.1)
To add actions for adding/removing linked items in the XSL, VYRE provides the following variables that can be used in the XSL style sheet:
- $link_add_action: prints a javascript function call that opens the popup window for selecting items to link to.
- $link_clear_action: prints a javascript function call for clearing all linked items.
- $link_remove_functionname: prints the name of a javascript function for removing a specific linked item. See note below.
- $linkDefinitionId: prints the ID of the current link definition.
- $link_move_functionname: (since 4.3.1.9) prints the name of a javascript function for moving the position of a specific item link. This takes in the link definition id, the id of the item thats position is being moved and the new position to move the item too. The positions are indexed from 0.
When printing an action to remove a single item from a list of linked items, something along the lines of the following should be used in the XSL:
href="javascript:{$link_remove_functionname}('{$linkDefinitionId}', '{@id}')"
Where {@id} is an XPath reference to the ID of the current item.
For more details on how to use javascript to link items in content templates read this article on Adding/removing linked items using hyperlinks
[edit] vyre-item:user-link
The following attributes can be used in this tag (one of id, name HAS to be specified):
- id - The ID of the link definition.
- name - The name of the link definition (that is, the name of the other end of the link definition).
- mode - [field/formatted] The editing mode. If set to "field", then the old drop-down list will be displayed. If set to "formatted", then XSL will be used to transform the list (and xslId or xslName MUST be specified).
- xslId - Only for mode="formatted". The ID of the XSL stylesheet to use (this must be a user list stylesheet).
- xslName - Only for mode="formatted". The name of the XSL stylesheet to use (this must be a user list stylesheet).
- elementId - Only for mode="formatted". The ID of the HTML element that contains the link list.
- cardinality - [one/many] Only for mode="field". Can be either "one" or "many", default is "one". Determines whether to display a multiple select box or not.
- saveType - Only for mode="field". Specifies how to save the links. Either "replace_existing" (default) or "add_to_existing".
- inputType - [select/detect_user/detect_parameter] Only for mode="field". Specifies how to get the link values. Defaults to "select". When "detect_parameter" is specified, then the link field will be hidden and the IDs of the users to link to will be retrieved from a request parameter by the name of "link_${linkDefinitionId}". When "detect_user" is specified, then the ID of the user currently logged in will be used.
- firstOptionEmpty - [true/false] Only for mode="field", inputType="select", cardinality="one". Specifies whether the first option in the select list should be an empty option (default is true).
- groupId - Only for mode="field". ID of a group to filter the options (optional).
- groupName - Only for mode="field". Name of a group to filter the options (optional).
- profileGroupId - Only for mode="field". ID of a profile group to filter the options (optional).
- profileGroupName - Only for mode="field". Name of a profile group to filter the options (optional).
To add actions for adding/removing linked items in the XSL, VYRE provides the following variables that can be used in the XSL style sheet:
- $link_add_action: prints a javascript function call that opens the popup window for selecting users to link to.
- $link_clear_action: prints a javascript function call for clearing all linked users.
- $link_remove_functionname: prints the name of a javascript function for removing a specific linked user. See note below.
- $linkDefinitionId: prints the ID of the current link definition.
When printing an action to remove a single user from a list of linked items, something along the lines of the following should be used in the XSL:
href="javascript:{$link_remove_functionname}('{$linkDefinitionId}', '{@profile-id}')"
Where {@profile-id} is an XPath reference to the Profile ID of the current user.
[edit] vyre-item:profile-group-link
The following attributes can be used in this tag:
- cardinality - Can be either "one" or "many", default is "one". Determines whether to display a multiple select box or not.
[edit] vyre-item:item-list
The following attributes can be used in this tag (one of id or name HAS to be specified):
- id - The ID of the item list definition.
- name - The name of the item list definition.
- xslId - The ID of the XSL stylesheet to use.
- xslName - The name of the XSL stylesheet to use.
- lightweight - If false, then the full content and metadata of the listed items will be loaded. Defaults to "true".
Item-List is treated as 'formatted', so you can't use mode="formatted".
To add actions for adding/removing listed items in the XSL, VYRE provides the following variables that can be used in the XSL style sheet:
- $item_list_definition_id: prints the ID of the current item list definition.
[edit] vyre-item:captcha-image (since 4.3)
This tag prints a CAPTCHA image, which can be used to prevent bot spamming. You will need to use the vyre-item:captcha-input as well to validate. The following attributes can be used in this tag:
- cssClass - name of a CSS class to use for the image tag, defaults to "captchaImage"
[edit] vyre-item:captcha-input (since 4.3)
This tag prints a CAPTCHA input box, where the user enters the text displayed by the vyre-item:captcha-image. The following attributes can be used in this tag:
- cssClass - name of a CSS class to use for the image tag, defaults to "captchaInput"
[edit] vyre-item:include (since 4.3.2)
This tag allows to include another resource (content template, bulk edit template, search template, static code, etc.) inside current template.
- templateId - the id of the template to include (must be a number).
[edit] vyre-item:message (since 4.3.2)
This tag, if included, sends an email message, as defined in Message templates. Please note that this tag will only send message when item is defined in the URL (e.g. ..../yourpage/item1234).
- msgTemplateId - the id of the template to use for sending (must be a number).
[edit] Localization
Localization values are used as follows:
<fmt:message key="my.locale.key"/>
Ensure that you import the JSTL formatting tag library by including the following line:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
[edit] portalAttributes
Portal attributes such as the context path can be retrieved and used as variables as follows:
<%
request.setAttribute("contextPath", vyre.publishing.portal.PortalAttributes.getInstance().getPortalContextPath());
%>
- ${contextPath}
