Reputation: 1
I'm working on a web project for my job and I'm attempting to add a Google survey to pages, by way of clicking a check box on the template side. The reason for this method is to add the script to all templates, but have the ability to turn it off/on on specific pages. If checked, show survey. If not, don't show survey.
My XSD schema boolean code is:
<xs:element name="ShowSurvey" type="xs:boolean"/>
This is the check box to be rendered on the publisher's template end.
My FTL code is:
<#if !Page.ShowSurvey>
<script type="text/javascript" async="" defer="" src="//survey.g.doubleclick.net/async_survey?site=#############"></script>
</#if>
When I go to regenerate the template, I get the following error message:
error regenerating rendition using TemplateName.ftl: freemarker.core.NonBooleanException: Error on line 13, column 23 in freemarker_template Expecting a boolean (true/false) expression here Expression Page.ShowSurvey does not evaluate to true/false it is an instance of freemarker.ext.dom.NodeListModel
What am I doing wrong? Could anyone shine some light on this?
Thanks in advance.
Upvotes: 0
Views: 327
Reputation: 31152
FreeMarker's XML wrapper is not XSD-aware, so you have a string like "true"
there, not a boolean. So you will have to convert it to boolean yourself. Something like <#if !xsdBool(Page.ShowSurvey)>
where xsdBool
is:
<#function xsdBool s>
<#if s == 'true' || s == '1'><#return true></#if>
<#if s == 'false' || s == '0'><#return false></#if>
<#stop "Malformed XSD boolean: " + s>
</#function>
Upvotes: 1