Special-taglibs

This documentation page describes advanced functions of the framework, that are designed for special application cases of more complex software designs.
Note: Please be aware, that within a tag definition only spaces are allowed as a seperator. Tabs or new line characters are not parsed and using them can lead to unrecognized error on tag definition analysis!

1. Iterator

The iterator tag was introduced in version 1.6 (final) to simplify the display mechanism of objects or associative arrays. For this reason an iterator tag defined within a template file must be filled by the document controller with the desired data. The definition of the tag looks as follows:
APF-Template
<html:iterator name=""> ... [<iterator:addtaglib namespace="" prefix="" class="" />] [<iterator:getstring namespace="" config="" entry="" />] ... <iterator:item [getter=""]> <item:placeholder name="" /> [<item:getstring namespace="" config="" entry="" />] [<item:addtaglib namespace="" prefix="" class="" />] </iterator:item> ... </html:iterator>
The <html:iterator /> tag defines the iterator and the <iterator:item /> tag contains the graphical description of how a data element should be displayed. Inside the data element a various number of placeholders and HTML tags (<item:placeholder />) can be defined. The name of the placeholder is equal to the name of the class attribute or array offset at the same time. In order to change the name of the get method, the optional tag attribut getter must be added to the <iterator:item /> tag definition. Please note, that the tag implementation uses the get() function as the default getter.

Description of the attributes:
  • name (1): Name of the iterators. (Allowed characters: [A-Za-z0-9])
  • getter: Name of the mathod that is used to retrieve an object's attribute. (Allowed characters: [A-Za-z0-9_])
  • name (2): Name of the place holder. (Allowed characters: [A-Za-z0-9])
To use the tag it must be announced using the
APF-Template
<core:addtaglib namespace="tools::html::taglib" prefix="html" class="iterator" />
directive. Further, the document controller of the Document in which the iterator is defined must inherit from the iteratorBaseController class located in the namespace tools::html::taglib::documentcontroller. The following code fragment shows, how to use the iterator tag:
PHP-Code
import('tools::html::taglib::documentcontroller','iteratorBaseController'); class list_controller extends iteratorBaseController { function list_controller(){ } function transformContent(){ ... // Get a reference om the iterator tag $Iterator = &$this->__getIterator('...'); // Fill the data container with a list of objects or associative arrays $Iterator->fillDataContainer(...); // Display on the place of definition ... $Iterator->transformOnPlace(); // ... or insert the content of the tag into a place holder $this->setPlaceHolder('...',$Iterator->transformIterator()); ... } }
In order to display language dependent value within the iterator (e.g. for language dependent table headers), the <iterator:getstring /> and <item:getstring /> tags can be used. The functionality is equal to the <html:getstring /> tag. If you are not comfortable with this tag, feel free to add your custom taglibs using the <iterator:addtaglib /> and <item:addtaglib /> tags. The functionality is equal to the <core:addtaglib /> tag.

2. Media stream tags

The media stream tags enable the developer to store and deliver GUI ressources directly from the namespace of a specific module. For this reason, the framework contains an abstract implementation of a streaming taglib and several dedicated taglibs, that generate a media url. Further, a generic front controller action is included, that streams the media files, that are requested by the tags.

In order to use the tags you must be sure, that the front controller action, that is intended to deliver the desired files, has a valid configuration for the current context. The action config is expected to be contained in the
Code
/config/tools/media/actions/{CONTEXT}/{ENVIRONMENT}_actionconfig.ini
file. The content of the file can be taken from the following code box:
APF-Konfiguration
[streamMedia] FC.ActionNamespace = "tools::media::actions" FC.ActionFile = "StreamMediaAction" FC.ActionClass = "StreamMediaAction" FC.InputFile = "StreamMediaInput" FC.InputClass = "StreamMediaInput" FC.InputParams = ""
A example configuration file is also included in the adventure-configpack-* release file under tools/media/actions/.

In order to generate dynamic media urls, the following taglibs are included in the framework:
  • form_taglib_mediastream: To be used within the html:form tag
  • html_taglib_mediastream: To be used within a template file
  • template_taglib_mediastream: To be used within the html:template tag
To be able to use one of the taglibs, the tag must be introduced to the desired scope using the <*:importdesign /> tags. The following code box shows an real life application example:
APF-Template
<core:addtaglib namespace="tools::form::taglib" prefix="html" class="form" /> <html:form name="TestFormular"> <form:addtaglib namespace="tools::media::taglib" prefix="form" class="mediastream" /> <img src="<form:mediastream namespace="modules::mymodule::pres::images" filename="phone_icon.png" />" alt="" /&t; <form:text name="phonenumber" /> <br /> <form:button name="send" value="Absenden" /> </html:form>
As you can take from the example above, the <*:mediastream /> tags expect the following attributes to be filled:
  • namespace: Namespace to the desired media file. (Allowed characters: [A-Za-z0-9:])
  • filename: Name of the media file. (Allowed characters: [A-Za-z0-9_.-])

Hint:
If you intend to manipulate the namespace of the file, that should be delivered, because you want to store the image files in the config namespace - using the context to give the application an individual touch - you have to acte like this:

  1. Add an id attribute to the desired tag:
    APF-Template
    <core:addtaglib namespace="tools::media::taglib" prefix="html" class="mediastream" /> <img src="<html:mediastream namespace="config::modules::mymodule::pres::images" filename="phone_icon.png" id="PhoneIcon" />" alt="" />
  2. Manipulate the namespaces within the responsible document controller:
    PHP-Code
    class example_controller extends base_controller { function transformContent(){ $mediaStreamTag = &$this->__getMediaStreamTagByID('PhoneIcon'); $mediaStreamTag->setAttribute($mediaStreamTag->getAttribute().'::'.$this->__Context); } function &__getMediaStreamTagByID($id){ $children = &$this->__Document->getChildren(); foreach($children as $objectId => $DUMMY){ if(get_class($children[$objectId]) == 'html_taglib_mediastream'){ return $children[$objectId]; } } $null = null; return $null; } }

3. Generic importdesign tag

Within more complex applications it is often necessary to fill the views - defined with the <*:importdesign /> tags - dynamically. In many cases, the developer thus wants to use model information of the application. To be able, to use the business layer as a real control layer, the framework features a generic importdesign tag, that allows you to retrieve the name of the template to include as well as the template's namespace from the desired application model dynamically.

The tag's signature looks like this:
APF-Template
<generic:importdesign modelnamespace="" modelfile="" modelclass="" modelmode="NORMAL|SINGLETON|SESSIONSINGLETON" namespaceparam="" templateparam="" [getmethod=""] [dependentactionnamespace="" dependentactionname="" [dependentactionparams=""]] />
The attributes have the following meaning:
  • modelnamespace: Namespace of the model class. (Allowed characters:: [A-Za-z0-9:])
  • modelfile: Name of the model class' file. (Allowed characters: [A-Za-z0-9_])
  • modelclass: Name of the model class. (Allowed characters: [A-Za-z0-9_])
  • modelmode: Creation mode of the model. (Allowed values: NORMAL|SINGLETON|SESSIONSINGLETON)
  • namespaceparam: Name of the model param, that returns the namespace of the template. (Allowed characters: [A-Za-z0-9_.-])
  • templateparam: Name of the model param, that returns the name of the template. (Allowed characters: [A-Za-z0-9_.-])
  • getmethod: Name of the model method, that should be used to query the template name and namespace of the template to include. Please note, that the method must expect one param that is given the value of the namespaceparam or templateparam attributes respectively and the tag expects that the function returns the value of the two parameters. By default, the getAttribute() function is used. (Allowed characters: [A-Za-z0-9_])
  • dependentactionnamespace / dependentactionname / dependentactionparams: These three options are intended to automatically register an action with the front controller. This functionality is helpful, if a module is included by the tag and a front controller action is used for navigation purposes.

    The attribute dependentactionnamespace defines the namespace of the action (e.g. sites::mysite::biz) and dependentactionname the name or the alias of the action (e.g. Navigate). dependentactionparams contains the params of the action like param1:value1|param2:value2. This format ist already known from the action configuration file layout.

In order to use the tag, you must first add the tag to the current scope by placing
APF-Template
<core:addtaglib namespace="tools::html::taglib" prefix="generic" class="importdesign" />
before the tag definition.

Notes:
  • As an real life application example the behind the site can be used. This article describes, how this documentation page is implemented and which tools of the framework are used.
  • If a front controller action is used for navigation purposes, the action class must set the class variable $__KeepInURL to true. This causes the FrontcontrollerLinkHandler to include the action and it's params to be included while url generation.
  • The registration of the action is only done, if the dependentactionnamespace and dependentactionname attributes are present in the tag definition and the action was not registered before. The action params attribute is optional.

4. core:appendnode tag

Within a discussion about reusable template fragments (e.g. forms), the idea occured to design a taglib, that can import various content to the scope of the current document. Thanks to the generic DOM structure of the GUI elements of the framework, this task is quite easy.

In order to provide a generic and reusable function, the 1.8 branch now features the <core:appendnode /> tag, that can import any content from a defined template. To use the tag, you must provide two attributes similar to the importdesign tag: namespace and template.

As of version 1.12, the optional attribut includestatic is available. It can be used to include all the content defined in the included template by setting it's value to true. In case the value contains any other value or the optional attribute is not defined, only the DOM nodes (instances of taglibs) of the included template are re-located.

4.1. Inclusion of templates

To include reusable fragments, the following code must be placed within the desired template:

APF-Template
<core:addtaglib namespace="core::pagecontroller" prefix="core" class="appendnode" /> <core:appendnode namespace="..." template="..." [includestatic="true" ]/>

If you want to reuse a special template, that is ised to display a domain object of your application, it is suitable to define this tag within a seperate template file (namespace: sites::testsite::pres::templates::generic; template: generic_templates). The tag definition my look like this:

APF-Template
<html:template name="ReusableTemplate"> ... <template:placeholder name="DisplayName"> ... </html:template>

In order to use the html template within another template file, the fragment can be included using the following tag definitions:

APF-Template
<core:addtaglib namespace="core::pagecontroller" prefix="core" class="appendnode" /> <core:appendnode namespace="sites::testsite::pres::templates::generic" template="generic_templates" />

4.2. Usage of the imported elements

The usage of the elements imported by the <core:appendnode /> tag is identical to the previous approach. This is because the elements are directly appended to the current children list within the DOM tree. Especially, the document controller's methods (e.g. __getTemplate()) can be used as well.

To address the template printed in chapter 4.1, the following code snippet can be used:

PHP-Code
$tmpl = &$this->__getTemplate('ReusableTemplate');

4.3. Important notes

Due to the fact, that template oarsing is done identically to the importdesign tag, the developer must care of the tags included in the special template. If necessary, tags have to be anounced using the adequate core:addtaglib statements.

Further, the tag creates transformation marker tags within the origin template, to enable the transformOnPlace() feature of the included tags supporting this. Please be aware, that the sequence of definition is equal to the marker tag order!

In case you want to include static content of the included template such as

APF-Template
<div class="formattingContainer"> <html:template name="ReusableTemplate"> ... </html:template> </div>

includestatic must be set to true.

Comments

Do you want to add a comment to the article above, or do you want to post additional hints? So please click here. Comments already posted can be found below.
There are no comments belonging to this article.