๐น About
Oracle APEX Template Directives are one of the most powerful features for creating dynamic, reusable, and conditional UI components directly inside templates.
They allow developers to:
โ
Add conditional rendering
โ
Loop through data
โ
Display dynamic content
โ
Simplify template customization
โ
Reduce JavaScript complexity
In this blog, weโll explore Oracle APEX Template Directives with practical examples and step-by-step implementation.
๐ ๏ธ Tools and Technologies
- Oracle APEX
- SQL
- HTML
- Template Directives
๐ What are Template Directives?
Template Directives are special instructions used inside Oracle APEX templates to dynamically render content.
They work similarly to conditional statements and loops in programming languages.
๐ฏ Why Use Template Directives?
Without template directives:
โ Large amount of duplicate HTML
โ Complex conditional rendering
โ More JavaScript code
โ Harder template maintenance
With template directives:
โ
Cleaner templates
โ
Better readability
โ
Dynamic rendering
โ
Easier customization
๐ Common Template Directives
| Directive | Purpose |
|---|---|
| {if/} | Conditional rendering |
| {case/} | Switch-case logic |
| {loop/} | Iterate over data |
| {with/} | Define local scope |
| {apply/} | Apply subtemplate |
๐ Where Can We Use Template Directives?
Template Directives can be used in:
โ
Region Templates
โ
Report Templates
โ
List Templates
โ
Cards
โ
Email Templates
โ
Content Rows
๐ Step-by-Step: How to Create Template Directives in Oracle APEX
โ Step 1: Create a Card Region
Go to:
Create Page โ Region โ Card RegionUse EMP table query:
SELECT empno, ename, job, sal, deptno FROM empโ Step 2: Body Formating
Go to:
Card Regionโ AttributesSet:
Body โ Advance Formating โ Enableor choose any custom report template.
โ Step 3: Enable Template Directives
Go to:
Body โ HTML ExpressionNow add Template Directive code.
๐ Example 1: Conditional Display Using IF
Suppose we want to display employee salary conditionally.
๐ HTML Expression
<div class="template-card-container">
<h3 class="u-textUpper u-bold" style="margin: 0 0 12px 0; font-size: 1.2rem; color: #1a2f3f;">
&ENAME.
</h3>
<div class="card-badge-container">
{if SAL/}
<span class="t-Badge t-Badge--success t-Badge--pill">
<span class="t-Badge-label">Salary: &SAL.</span>
</span>
{else/}
<span class="t-Badge t-Badge--danger t-Badge--pill">
<span class="t-Badge-label">No Salary</span>
</span>
{endif/}
</div>
</div>โ Result
If SAL contains value:
โ Green badge displays
Else:
โ Red badge displays
๐ Example 2: CASE Directive
CASE directives work like switch-case logic.
๐ HTML Expression
{case JOB/}
{when MANAGER/}
<span class="fa fa-user-tie"></span>
Manager
{when ANALYST/}
<span class="fa fa-chart-line"></span>
Analyst
{when CLERK/}
<span class="fa fa-user"></span>
Clerk
{otherwise/}
Employee
{endcase/}โ Result
Different icons display based on JOB value.
๐ Example 3: Conditional CSS
๐ HTML Expression
<div class="
{if DEPTNO/}
dept-active
{else/}
dept-inactive
{endif/}">
#ENAME#
</div>๐ Example 4: Highlight High Salary Employees
๐ SQL Query
SELECT
empno,
ename,
sal,
CASE
WHEN sal > 3000 THEN 'HIGH'
ELSE 'NORMAL'
END salary_status
FROM emp๐ HTML Expression
<div class="
{case SALARY_STATUS/}
{when HIGH/}
high-salary
{otherwise/}
normal-salary
{endcase/}">
#ENAME#
</div>๐ Example 5: LOOP Directive
LOOP directives are useful in advanced templates.
๐ Example
{loop EMPLOYEES/}
<div>
#ENAME#
</div>
{endloop/}๐ Example 6: WITH Directive
The WITH directive creates reusable local variables.
๐ Example
{with EMP_NAME:=ENAME/}
<h2>&EMP_NAME.</h2>
{endwith/}๐ Example 7: APPLY Directive
Used to apply reusable subtemplates.
๐ Example
{apply EMP_TEMPLATE/}๐ฏ Real-World Use Cases
Template Directives are extremely useful for:
โ Employee dashboards
โ Status-based cards
โ Notification panels
โ Dynamic badges
โ Role-based UI
โ Custom reports
๐จ Example CSS
Add this CSS in:
Page โ CSS โ Inline.high-salary {
background: #d4edda;
padding: 10px;
border-radius: 10px;
}
.normal-salary {
background: #f8d7da;
padding: 10px;
border-radius: 10px;
}โ ๏ธ Important Considerations
๐น Use Correct Syntax
Template directives are case-sensitive.
Incorrect syntax may break rendering.
๐น Avoid Heavy Business Logic
Use directives mainly for UI rendering.
Keep business logic in:
โ
SQL
โ
PL/SQL
๐น Test Nested Directives Carefully
Complex nested directives can become difficult to debug.
๐ Advanced Use Cases
You can use Template Directives for:
โ Dynamic Cards
โ Report Formatting
โ Email Templates
โ Dashboard Widgets
โ Notification Systems
โ Dynamic Icons
๐ Workflow
SQL Query
โ
Template Directive Processing
โ
Dynamic HTML Rendering
โ
Final UI Output๐ฅ Why Oracle APEX Developers Love Template Directives
Template Directives help developers create dynamic user interfaces without writing excessive JavaScript.
Benefits include:
โ
Reusable templates
โ
Cleaner HTML
โ
Better maintainability
โ
Flexible rendering
๐ Conclusion
Oracle APEX Template Directives are a powerful feature for building intelligent and dynamic UI components.
Using directives like:
โ
IF
โ
CASE
โ
LOOP
โ
WITH
โ
APPLY
developers can create highly customizable templates with minimal effort.
If you want cleaner templates and smarter rendering in Oracle APEX, Template Directives are definitely worth learning.
Happy Coding!
Hi, Iโm Ankur Rai, an Oracle APEX Developer with 6+ years of professional experience in building enterprise applications. I specialize in creating scalable and efficient solutions using Oracle APEX, PL/SQL, and SQL to solve real-world business challenges.
I am a 3X Oracle APEX Professional Certified Developer and also an Oracle ACE Associate Member, actively contributing to the Oracle community by sharing knowledge, insights, and best practices. Through my blogs, I aim to help developers learn, grow, and build better Oracle APEX applications together.




