Saturday, June 3, 2017

PHP Tag Lib: PHP Custom Tag Library (TagLib)

We use tag in your HTML page such as "DIV", "H2", "P" etc in every moment in our life. Who used Grail's or Spring MVC he has knowledge on custom tag library. We can also use custom tag lib in PHP project. Below is a example of PHP custom tag lib usage:

<tglib:upper>Goes to upper</tglib:upper>

To drive output of this custom tag in PHP, you have to download and include tag lib library first from below link:

drive.google.com/PHP Tag Lib: PHP Custom Tag Library (TagLib)

We used tglib:upper in above script, so we have to make a directory in "TagLib" directory named "upper" with a function named "tglib___upper" that support $tag parameter. With will supply tag name as well as any attributes in that tag. 

Below is a sample example of "upper" tag:

function tglib___upper($tag)
{
    return strtoupper($tag['content']);
}


$tag["content"] contains body parts of the tag.

If you download and execute "tag1.php" file, below output will be generated:





No comments:

Post a Comment