Index: magnolia-core/src/main/java/info/magnolia/freemarker/models/NodeDataModelFactory.java =================================================================== --- magnolia-core/src/main/java/info/magnolia/freemarker/models/NodeDataModelFactory.java (revision 41137) +++ magnolia-core/src/main/java/info/magnolia/freemarker/models/NodeDataModelFactory.java (revision ) @@ -79,7 +79,7 @@ final String s = nodeData.getString(); try { final String transformedString = LinkUtil.convertLinksFromUUIDPattern(s); - return new SimpleScalar(transformedString); + return new StringMultitypeModel(transformedString); } catch (LinkException e) { throw new RuntimeException("Failed to parse links in " + nodeData, e); } Index: magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java =================================================================== --- magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java (revision 41137) +++ magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java (revision ) @@ -251,6 +251,25 @@ assertRendereredContent("yes yes no no", c, "test.ftl"); } + public void testStringsCanBeExposedAsBooleans() throws Exception { + final MockContent c = new MockContent("root"); + final MockContent foo = new MockContent("foo"); + foo.addNodeData(new MockNodeData("hip", Boolean.TRUE)); + foo.addNodeData(new MockNodeData("hop", "true")); + foo.addNodeData(new MockNodeData("lala", "random string")); + foo.addNodeData(new MockNodeData("zuzu", "false")); + foo.addNodeData(new MockNodeData("check", false)); + c.addContent(foo); + tplLoader.putTemplate("test.ftl", "" + + "[#if foo.hip]oh yeah, [/#if]" + + "[#if foo.hop]that too[/#if]" + + "[#if foo.lala]not this, [/#if]" + + "[#if foo.zuzu]and this[/#if]" + + "[#if foo.check]neeeee[/#if]."); + + assertRendereredContent("oh yeah, that too.", c, "test.ftl"); + } + public void testDatePropertiesAreHandledProperly() throws TemplateException, IOException { final MockContent c = new MockContent("root"); final MockContent foo = new MockContent("foo"); Index: magnolia-core/src/main/java/info/magnolia/freemarker/models/StringMultitypeModel.java =================================================================== --- magnolia-core/src/main/java/info/magnolia/freemarker/models/StringMultitypeModel.java (revision ) +++ magnolia-core/src/main/java/info/magnolia/freemarker/models/StringMultitypeModel.java (revision ) @@ -0,0 +1,74 @@ +/** + * This file Copyright (c) 2011 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. + * + * + * This file is dual-licensed under both the Magnolia + * Network Agreement and the GNU General Public License. + * You may elect to use one or the other of these licenses. + * + * This file is distributed in the hope that it will be + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. + * Redistribution, except as permitted by whichever of the GPL + * or MNA you select, is prohibited. + * + * 1. For the GPL license (GPL), you can redistribute and/or + * modify this file under the terms of the GNU General + * Public License, Version 3, as published by the Free Software + * Foundation. You should have received a copy of the GNU + * General Public License, Version 3 along with this program; + * if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * 2. For the Magnolia Network Agreement (MNA), this file + * and the accompanying materials are made available under the + * terms of the MNA which accompanies this distribution, and + * is available at http://www.magnolia-cms.com/mna.html + * + * Any modifications to this file must keep this entire header + * intact. + * + */ +package info.magnolia.freemarker.models; + +import freemarker.template.TemplateBooleanModel; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateScalarModel; +import org.apache.commons.lang.BooleanUtils; + +import java.io.Serializable; + +/** + * A model wrapper which exposes Strings as "simple scalars" as well as booleans. + * + * + * @author gjoseph + * @version $Revision: $ ($Author: $) + */ +public class StringMultitypeModel implements TemplateScalarModel, TemplateBooleanModel, Serializable { + + private final String value; + + public StringMultitypeModel(String value) { + this.value = value; + } + + public String getAsString() { + return (value == null) ? "" : value; + } + + /** + * @see org.apache.commons.lang.BooleanUtils We use BooleanUtils instead of Boolean.parseBoolean to allow "y", "yes" and "on", + * thus staying close to content2bean (although content2bean uses org.apache.commons.beanutils.converters.BooleanConverter, + * which also allows "1" for true) + */ + public boolean getAsBoolean() throws TemplateModelException { + return BooleanUtils.toBoolean(value); + } + + public String toString() { + return value; + } +}