Manually Setting Execution Mode

As you know (hopefully!), custom tags in CF can be run in multiple execution modes. Specifically, you can build a custom tag so that you can call it like so:

<FONT COLOR=MAROON><cf_bold></FONT>
Foo
<FONT COLOR=MAROON></cf_bold></FONT>

Your custom tag can check to see which mode it is being called in by using a built-in scope, ThisTag:

<FONT COLOR=MAROON><cfif thisTag.executionMode is <FONT COLOR=BLUE>"start"</FONT>></FONT>
   <FONT COLOR=NAVY><b></FONT>
<FONT COLOR=MAROON><cfelse></FONT>
   <FONT COLOR=NAVY></b></FONT>
<FONT COLOR=MAROON></cfif></FONT>

The executionMode key will be set to start when the tag is run the first time, and end when the tag is closed up with a matching pair. But what if you need to specifically call the tag in it’s “end” mode? You can’t set the value of thisTag.executionMode directly. However, you could tweak your code slighty like so:

<FONT COLOR=MAROON><cfparam name=<FONT COLOR=BLUE>"attributes.executionMode"</FONT> default=<FONT COLOR=BLUE>"#thisTag.executionMode#"</FONT>></FONT>

<FONT COLOR=MAROON><cfif attributes.executionMode is <FONT COLOR=BLUE>"start"</FONT>></FONT>
   <FONT COLOR=NAVY><b></FONT>
<FONT COLOR=MAROON><cfelse></FONT>
   <FONT COLOR=NAVY></b></FONT>
<FONT COLOR=MAROON></cfif></FONT>

Now you override the execution mode of your custom tag on a case by base basis:

<FONT COLOR=MAROON><cf_bold></FONT>
Foo
<FONT COLOR=MAROON></cf_bold></FONT>

<FONT COLOR=MAROON><cf_bold executionMode=<FONT COLOR=BLUE>"start"</FONT>></FONT>
Another Foo
<FONT COLOR=MAROON><cf_bold executionMode=<FONT COLOR=BLUE>"end"</FONT>></FONT>
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments