2.3. Tags

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 prefixClass nameFile pathDescription
cPhable_CT_STL_CorePhable/taglibs/STL/Core.phpcore taglibs, equivalent to JSTL
wpPhable_CT_MWT_WP_TagsPhable/taglibs/MWT/WP_Tags.phpwordpress taglibs
mwtPhable_CT_MWT_TagsPhable/taglibs/MWT/Tags.phpmwt tags to enhance multiserving and adaptation
htPhable_CT_MWT_HyperTextPhable/taglibs/MWT/HyperText.phpXHTML 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"/>
								
				

Note

  • Notice in the above example that the set tag is prefixed with "c": this is the prefix for all Core tags.
  • Even though c:set is a bodyless tag, in order not to break the XML syntax you still need to close it, notice the trailing slash

The next example shows how to fill a select in a HTML form dynamically:

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