I was reading somewhere that PHP is a templating language. What is exactly a templating language? What makes PHP one? What are the other templating languages?
Advertisement
Answer
The premise behind a template language is that the language is “embedded” within some other master document. Specifically, on your average document, the total size of the document is mostly document source than template language.
Consider two contrived examples:
print "This is a simple document. It has three lines." print "On the second line is my name: " + firstName print "This is the third line."
vs
This is a simple document. It has three lines. On the second line is my name: $firstName This is the third line.
You can see in the first example, the language wraps the document text. In the second example, the document text is the most prevalent, with just a little bit of code.
Some template languages are full blown general purpose languages, such as PHP, ASP.NET, and Java’s JSP. Others are more limited designed specifically for templating, such as Velocity and FreeMarker (both utilities for Java).
Many word processors, such as Microsoft Word, have their own templating capabilities, commonly referred to as “Mail Merge”.