# The Power of APEX Template Directives

Oracle APEX Template Directives allow us to move data formatting from SQL to HTML, creating easier-to-read queries, improving performance, and reducing the risk of Cross-Site Scripting attacks.  
  
Template Components can be used on any component with the HTML Expression, and we have the following options:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716886477229/611d5d8f-8915-4bf0-bfc9-e9e292c2f941.png align="center")

1. IF: For the IF example we are going to use the DISABLE\_FLAG column. If there the column is not null will return Yes else NO.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716886752184/b2fbfe23-aaf7-462f-93bd-7c65edb949ea.png align="center")
    
    Token Modifiers
    
    | Condition | Directive |
    | --- | --- |
    | if\_exists\_and\_true | `{if ITEM/}` |
    | if\_exists | `{if ?ITEM/}` |
    | if\_not\_exists\_or\_false | `{if !ITEM/}` |
    | if\_not\_exists | `{if !?ITEM/}` |
    | if\_not\_false | `{if =ITEM/}` |
    | if\_exists\_and\_false | `{if !=ITEM/}` |
    
2. CASE: For the CASE we are going to use the GENDER column. When M we will show the fa-male icon and fa-female when the value is F.  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716887037779/30314170-0440-47f3-ab8c-d8cf3b44c45b.png align="center")
    
3. LOOP: For the LOOP, the column BADGES contains colon-separated values representing all the badges the user has. We are going to break that into &lt;li&gt; elements and add the fa-trophy icon.  
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716887238995/70672e42-af74-4d16-a30a-c50f665724a5.png align="center")
    
    The code above will return the following:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716887355360/7252c855-fa64-4409-bf19-07dbc1553d0c.png align="center")
    
4. WITH and APPLY allow us to add predefined template component plugins and use them inside a template component (nested template component) or in HTML Expressions. In the example below, we will use the BADGE template component plugin to show the value of the FULL\_NAME column.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716887638549/a4a84d4f-d100-40e2-b25c-c996531d0dff.png align="center")
    
    The code above will return the following:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716887681852/d363a591-383c-420d-a570-e8d582e857d7.png align="center")
    
    To help us build the WITH/APPLY and add all the custom attributes for each plugin, @[Matt Mulvaney](@lufcmattylad) created the [Template Component With/Apply Generator](https://apex.oracle.com/pls/apex/r/luf/with-apply-generator/home) This tool is very helpful for generating the WITH/APPLY for each plugin
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716888016057/2c96c11c-9c14-48be-9981-8a9987cca956.png align="center")
    
    ##
