Referencing HTTP headers in a Freemarker template


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


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:

Freemarker template (e.g. hook_pre_process.groovy)
<#ftl encoding="utf-8" />
<#import "/web/templates/modernui/funnelback_classic.ftl" as s/>
<#import "/web/templates/modernui/funnelback.ftl" as fb/>
<html lang="en">
         <#assign  mtype=httpRequest.getHeader('X-Funnelback-form')>
         <#if mtype == "mobile">
             <#include "simple-mobile.ftl">
             <#include "simple-basic.ftl">