Tags have the same syntax of XML tags: they must have a closing tag or a final / if they are bodyless, they can have any number of attributes and attributes values must be enclosed in double-quotes. Inside a value you must use the entity " if you want to use double-quotes.
When the taglib engine processes a tag it calls the methods of the PHP class representing the tag, passing all attributes names and values in the method call. A single PHP class can implement several tags, each method implementing one of them. Tags are normally grouped together and their names prefixed by a common string. This prefix is used by the taglib engine to map a tag to the PHP class (and file) that implements it.
As shown in the following table MWT groups taglibs in four different classes:
| Tag prefix | Class name | File path | Description |
|---|---|---|---|
| c | Phable_CT_STL_Core | Phable/taglibs/STL/Core.php | core taglibs, equivalent to JSTL |
| wp | Phable_CT_MWT_WP_Tags | Phable/taglibs/MWT/WP_Tags.php | wordpress taglibs |
| mwt | Phable_CT_MWT_Tags | Phable/taglibs/MWT/Tags.php | mwt tags to enhance multiserving and adaptation |
| ht | Phable_CT_MWT_HyperText | Phable/taglibs/MWT/HyperText.php | XHTML tags |
In the Tags reference all tags will be explained in detail.
For now it is important to underline that the Core taglibs (first row of the table above) provide scripting functionalities: set variables in pages, get variables values, control execution flow, etc. It's also time to see tags in action, as an example the next line shows how to set a variable in a page by using the Core taglibs:
<c:set var="varname" value="varvalue"/>
The next example shows how to fill a select in a HTML form dynamically:
Example 2.1. Filling a select dynamically with core taglibs
<form action="#" method="post">
<select name="year">
<c:forEach var="year" begin="1970" end="2050">
<option value="${year}">${year}</option>
</c:forEach>
</select>
</form>
For those that are already wondering about the syntax used to enclose the year variable, this is the expression language, explained in the following paragraph.
Going back to the taglibs summary table above, a few words need to be said about ht taglibs. These tags are used to manipulate standard XHTML tags and this is also the only case where the tag prefix, ht, is not necessary. This means that if for example you want to use the IMG tag to put an image in a widget you can write:
<ht:img src="myimage.gif"/>
Or, as you would normally do in XHTML:
<img src="myimage.gif"/>
Just remember to close the IMG tag, as you would do in XHTML. In this way you can write XHTML pages as you have always done, but you are actually writing taglibs.
In this paragraph we have described the basics characteristics of taglibs and we have listed the taglibs currently supported by MWT. It's important to underline that you can always extend taglibs by writing your own tahs and importing your the taglibs in your pages. This is descrined in paragraph Writing your own taglibs