Composum Nodes Taglib (cpn)
These are general tags contained in Composum Nodes that can be used in rendering pages and dialogs, and are used widely in the various parts of the Composum Platform itself.
anchor
Embeds an anchor link tag
Attributes
-
name
if set, this is used instead of tag name 'a'.
-
classes
deprecated: use 'class' like a normal HTML tag
-
test
an EL expression that determines whether the tag is shown
Examples
-
<cpn:anchor test="${not empty model.anchor}" name="${model.anchor}" title="${model.title}"/>
Renders an anchor with the name given by model.anchor , if that is not empty. The title attribute is a dynamic attribute - it has no special function in the tag, but is just rendered into the output.
bundle
Declares the topmost resource bundle for i18n translation in the current requests resource bundle stack.
Attributes
-
basename
the Java Resource Bundle base name
Examples
-
<cpn:bundle basename="ist-composum-site"/>
selects the Resource Bundle with the base name 'ist-composum-site' as the topmost resource bundle in the requests processing; this resource bundle is now the first in the chain for translations
clientlib
Includes a clientlib reference (JS, CSS etc).
Client libraries are folders of sling:resourceType composum/nodes/commons/clientlib containing subfolders for each type, and declare dependencies to other client libraries. The tag can reference multiple client libraries if they are referenced by category, and if the client library/-ies have dependencies to other client libraries / resources. Thus, the tag can render as several link / script / img tags.
see: Clientlibs
Attributes
-
test
nothing is rendered if the test attribute value is ‚false‘ (general condition)
-
category
the category of client library to be included; one of category or path is required but categories are preferred and more flexible
-
path
the repository path to reference the client library to be included; one of category or path is required
-
type
type of rendered resources: css, js, link, img, png, jpg
Examples
-
<cpn:clientlib type="link" category="${model.viewClientlibCategory}"/> <cpn:clientlib type="css" category="${model.viewClientlibCategory}"/> <cpn:clientlib type="css" test="${model.editMode}" category="${model.editClientlibCategory}"/>
a typical HTML head snippet to include header link tags ans styles; the edit mode styles are included only if the 'editMode' check returns 'true'
-
<cpn:clientlib type="js" category="${model.viewClientlibCategory}"/> <cpn:clientlib type="js" test="${model.editMode}" category="${model.editClientlibCategory}"/>
the analogous example for the include of clientlib JS code - typically at the end of the HTML body
component
Creates a JSP / Java variable of an instance of a Java Bean class (model class). The variable is declared only in the body of the component tag. Each variable of the same name in the specified scope if hided during tag processing and restored on the tags end.
Attributes
-
var
the name of the variable; this name must be unique in the declared scope
-
type
the complete class name of the Java class of the instance to create
-
scope
the scope of the variable declaration; the variable is declared inside of the component tag body and in this specified scope.
- page: JSP page scope (default)
- request: available in the page and all included components
- session: the variable is available during session lifetime
In each case the availability of the variable is limited by the tag boundaries.
-
replace
If 'true' a new instance is created and set as variable. If 'false' the variable is created only of not existing in the specified scope and reused if always available with a compatible type.
In the 'page' scope the default is 'true' otherwise 'false'. So you can declare a variable in request scope for a set of components in the include tree which is declared in each component which needs this and shared nevertheless independently from the creating script.
Examples
-
<cpn:component var="model" type="my.project.model.ComponentModel"> <cpn:text value="${model.description}"/> ... </cpn:component> <%-- 'model' not available outside the component tag --%>
Provides an instance of the specified type as variable 'model' in the page scope.
-
<cpn:component var="model" type="my.project.model.ComponentModel" scope="request"> <sling:include path="child"/> </cpn:component>
The declared variable 'model' is also available in the script code of the included component. If the script of the included component declares the the variable 'model' also in request scope and of the same type (and without 'replace="true"') the instance declared here and its current state is shared with the 'child' component.
defineObjects
An extension of the sling:defineObjects tag.
Examples
-
<cpn:defineObjects/>
Creates additional variables:
- pagesAccessAuthor , pagesAccessPreview , pagesAccessPublic : boolean variables that are true if the request runs in access mode author / preview / public , respectively.
- pagesModeNone, pagesModePreview, pagesModeEdit, pagesModeDevelop : boolean variables that are true if the request runs in display mode none, preview, edit or develop, respectively.
div
The ‚div‘ tag is rendering a HTML div tag if the condition (‚test’ attribute) is ‚true‘.
Attributes
-
test
nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)
-
body
if the ‚body‘ condition is true the tags body is rendered even if the general ‚test‘ condition is ‚false’ - the 'conditional tag around' case
-
tagName
the HTML tag name; if ‚none‘ no tag is rendered around the body
-
class
the CSS class attribute of the HTML tag
-
...
each dynamic attribute with a non null value is rendered as it is in the HTML tag
Examples
-
<cpn:div test="${model.divAround}" body="true" class="div-around"> ... </cpn:div>
Is rendering the 'div' tag if the 'model.isDivAround()' returns 'true'; the body is rendered always even if the 'test' condition is not true.
-
<cpn:div test="${model.notEmpty}" class="...">...</cpn:div>
Is rendering the div tag and its body only if the 'model.isNotEmpty()' method returns 'true'.
form
Generates form elements with mapped action URLs
Attributes
-
action
the action URL to send the form data; this URL is mapped (resolver.map()) automatically
-
method
the HTTP method of the form request
-
enctype
the encoding type of the form request data set ('enctype' attribute of the HTML form tag)
-
charset
the value of the HTML form 'accept-charset' attribute
-
test
nothing is rendered if the test attribute value is ‚false‘ (general condition)
-
...
each dynamic attribute with a non null value is rendered as it is in the HTML tag
Examples
-
<cpn:image classes="${fileCssBase}_image" src="${file.path}" draggable="false"/>
renders a HTML anchor tag to the resource path with additional tag attributes; the resources path is mapped automatically
image
Rendering of an image HTML tag with resolver mapping of the image URL.
Attributes
-
test
nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)
-
src
the image URL / URI / path; an external URL is rendered as it is a path or URI is mapped using the Sling resource resolver
-
map
the on/off switch for the resolver mapping
-
format
an optional format rule to prepare the URL before rendering; useful for example if a resource path in the 'src' attribute should be embedded in a service URL
-
class
the CSS class attribute of the HTML tag
-
...
each dynamic attribute with a non null value is rendered as it is in the HTML tag
link
Rendering of an anchor HTML tag (hyperlink) this resolver mapping of the link URL ('href' attribute).
Attributes
-
test
nothing (exception: the ‚body‘ is ‚true‘) is rendered if the test attribute value is ‚false‘ (general condition)
-
body
if the ‚body‘ condition is true the tags body is rendered even if the general ‚test‘ condition is ‚false’ - the 'conditional link around' case
-
href
the target URL / URI / path; an external URL is rendered as it is, a path or URI is mapped using the Sling resource resolver
-
map
the on/off switch for the resolver mapping
-
format
an optional format rule to prepare the URL before rendering; useful for example if a resource path in the 'href' attribute should be embedded in a service URL
-
class
the CSS class attribute of the HTML tag
-
...
each dynamic attribute with a non null value is rendered as it is in the HTML tag
Examples
-
<cpn:link href="${target}" format="/bin/pages.html{}">${cpn:path(target)}</cpn:link>
Renders a link to a page resource for editing with the 'Pages' editor.
-
<cpn:link test="${condition}" body="true" href="${target}"> <div class="...">...</div> </cpn:link>
a conditional link around a 'div'; the body (the 'div' inside of the tag) is always rendered but the link around only if condition is 'true'
text
The ‚text‘ tag ist the general tag to embed text values in the HTML output. The value is normally escaped to prevent from XSS attacks. If the value is empty (or null) nothing is rendered. It’s possible to format the value before escaping and rendering.
Attributes
-
test
nothing is rendered if the test attribute value is ‚false‘ (general condition)
-
escape
the general on/off switch for text escaping
-
type
the text type to select the escape rule:
- text: HTML text escaping (default)
- rich: rich text escaping (text formatting and simple HTML tags allowed)
- path: repository path (URI) encoding
- script: ECMA script escaping
- style: CSS code escaping
- cdata: wrap value with
- value: no escaping!
-
value
the text value to render; if not present the 'property' attribute is used
-
property
the name of a property of the current resource to retrieve the text value; used if no value attribute is specified; if no value found and no property declared the text tag body content is rendered as text (without formatting)
-
format
format pattern string ‚{fmt-type}..format..‘ to prepare the text value with {fmt-type}:
- {Message}: a Message text formatter is used
- {Date}: a SimpleDateFormat formatier is used
- {String}: a string formatter is used
- {Log} (or nothing and at least one ‚{}‘ pattern in the format): a Log formatter is used
-
i18n
if ‚true‘ the text value is translated using the requests locale and the requests resource bundle stack; if a format is specified the format is translated before formatting - in this case the value is translated separately before formatting
-
locale
the locale to use to create the formatter for the specified format
-
tagName
the HTML tag name; if ‚none‘ no tag is rendered around the value
-
class
the CSS class attribute of the HTML tag
-
...
each dynamic attribute with a non null value is rendered as it is in the HTML tag
Examples
-
<cpn:text value="${model.title}"/>
a simple text rendering example (escaped as HTML text)
-
<cpn:text property="stringValue" format="{String}a string: '%s'" i18n="true"/>
a formatted text value rendering; if stringValue is not empty the text is rendered with HTML escaping embedded in the format string; the format and the value are translated before formatting if a matching translation can be found