Lucee allows extending the language with custom tags to add functionality to view templates . Custom tags are typically used for view logic. Custom tags are created with CFCs and then imported into a view, or Application .cfc
This article shows a brief example, then read these additional articles:
Calling Custom Tags
Creating Custom Tags
Example View with a Custom Tag
Consider the following HTML template which uses a custom tag, called greeting.
```
A Basic Custom Tag Example
```
When running this script, it will output:
Hello Jim Smith,
The time is 06:43 AM
The .cfm html template used a custom tag called greeting, passed a firstname & lastname to it, and the greeting tag generated the text for output.
Here is what the greeting.cfc custom tag looks like. The article on Creating Custom Tags explains in depth.
```
component {
/**
* Invoked during the start of the custom tag
* @param {struct} required struct attributes The attributes passed to the custom tag
* @param {struct} required struct caller A reference to the variables scope from the location that calls the custom tag
* @return {boolean} To control whether to execute the body of the custom tag
*/
public boolean function onStartTag(required struct attributes, required struct caller){
param name="attributes.firstName";
param name="attributes.lastName";
writeOutput("Hello #attributes.FirstName# #attributes.lastName#,
");
writeOutput("The time is #timeFormat(now(), "hh:mm tt")#
");
return false;
}
/**
* Invoked after the completion of the closing tag
* @param {struct} required struct attributes The attributes passed to the custom tag
* @param {struct} required struct caller A reference to the variables scope from the location that calls the custom tag
* @param {string} string output The output generated between the start and end tags at the caller
* @return {boolean} To control whether to execute the body of the custom tag
*/
public boolean function onEndTag(required struct attributes, required struct caller, string output){
return false;
}
}
```