Referencing HTTP headers in a Freemarker template

Managed by | Updated .

Background

This article explains how to access HTTP headers from within a Freemarker template.

Example

The data model includes a hidden httpRequest object that can be referenced from with Freemarker templates.

The following code reads a custom http header attribute (X-funnelback-form) and uses this as a condition within an if statement:

<#ftl encoding="utf-8" />
<#import "/web/templates/modernui/funnelback_classic.ftl" as s/>
<#import "/web/templates/modernui/funnelback.ftl" as fb/>
<html lang="en">
     <head>
         <#assign  mtype=httpRequest.getHeader('X-Funnelback-form')>
         <#if mtype == "mobile">
             <#include "simple-mobile.ftl">
         <#else>
             <#include "simple-basic.ftl">
        </#if>
     </head>
     <body></body>
</html>
Was this artcle helpful?

Tags
Type: Keywords:
Features: Frontend > Modern UI Frontend > Freemarker

Comments