Referencing HTTP headers in 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:
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">
<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>