SoFunction
Updated on 2025-04-14

Coldfusion MX Skill Essence Collection 2 Page 2/6


Use custom tags to set layout configuration
ColdFusion’s custom labeling feature allows you to encapsulate any feature you imagine into a simple and easy-to-use package. Although this feature was one of the functions of the ColdFusion server a few years ago, starting from version 4.0, you can use the start and ending volume tags in your custom volume tags. In order to illustrate how to use custom start and ending labels, in the following example, we wrap the web content in a custom label and provide related functions of layout configuration and formatting.

Think about it, wouldn’t it be great if you can use the following writing method in a normal page?

<CF_FormatPage Title="My Page Title">
Here is the content of the main area of ​​your page. Please note that we have not added forms or <BODY> tags here.

</CF_FormatPage> 

This is how the original code of the entire page is. All other layout configuration and formatting information are hidden in the custom label outside the main content. In order to be able to use the start and ending labels in your custom label, you must first understand the two usage statuses of the custom label. You can use the value of this variable to determine whether the start or ending volume is currently being used. Basically, your custom label content will be executed twice: once when you encounter the starting label, and the other time when you encounter the ending label. In order not to make this article seem too verbose, we do not add too much formatted related program code here, but the following basic CF_FormatPage custom tag should be enough to let you understand the concepts we just mentioned:

<!--- The following is the content of the CF_FormatPage custom label file --->
<!--- If the execution mode is "Start", it means that we are encountering the start volume label, so we display the first half of the page format --->
<CFIF  IS "Start"> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 

<HTML>
<HEAD>
<TITLE><CFOUTPUT>##</CFOUTPUT></TITLE>
</HEAD> 

<BODY> 

The above paragraph can contain page title pictures, menus or other content.

<!--- Other contents contained in this tag will be displayed here --->

<!--- If the execution mode is "End", it means we have encountered the ending volume label, so we display the second half of the page format --->
<CFELSEIF  IS "End"> 

<BR><BR>This is the end of the page area, where you may put content links or copyright declaration text.

</BODY>
</HTML> 

</CFIF> 

Of course you can do more than this simple example, such as adding dynamic menus, adding different title images for each page, and so on. Or in another way, you can create different custom labels for different situations to encapsulate the layout configuration, as long as it can meet your specific needs.
Previous page123456Next pageRead the full text