Index: magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java =================================================================== --- magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java (revision 39061) +++ magnolia-core/src/test/java/info/magnolia/freemarker/FreemarkerHelperTest.java (working copy) @@ -652,14 +652,20 @@ assertRendereredContentWithoutCheckingContext("Coco: FooBar says hello", new HashMap(), "test.ftl"); } - public void testEnums() throws Exception { + public void testEnumMembersCanBeUsedInTemplates() throws Exception { fmConfig.addSharedVariable("chalala", Chalala.class); - // TODO : not really - // tplLoader.putTemplate("test.ftl", "3: ${chalala.three}"); - // TODO, but: - tplLoader.putTemplate("test.ftl", "list enum values: [#list chalala.enumConstants as val]${val} [/#list]"); + tplLoader.putTemplate("test.ftl", "3: ${chalala.three}"); + assertRendereredContentWithoutCheckingContext("3: three", new HashMap(), "test.ftl"); + } - assertRendereredContentWithoutCheckingContext("list enum values: one two three ", new HashMap(), "test.ftl"); + public void testEnumCanBeListed() throws Exception { + fmConfig.addSharedVariable("chalala", Chalala.class); + tplLoader.putTemplate("test.ftl", + "list enum by keys: [#list chalala?keys as val]${val} [/#list]\n" + + "list enum by values: [#list chalala?values as val]${val} [/#list]"); + assertRendereredContentWithoutCheckingContext( + "list enum by keys: one two three \n" + + "list enum by values: one two three ", new HashMap(), "test.ftl"); } public void testCanAccessEnumPropertiesOfVariables() throws Exception { Index: magnolia-core/src/main/java/info/magnolia/freemarker/models/MagnoliaObjectWrapper.java =================================================================== --- magnolia-core/src/main/java/info/magnolia/freemarker/models/MagnoliaObjectWrapper.java (revision 39061) +++ magnolia-core/src/main/java/info/magnolia/freemarker/models/MagnoliaObjectWrapper.java (working copy) @@ -85,14 +85,22 @@ // handleUnknownType() will relay to our ContextModelFactory. return handleUnknownType(obj); } + + if (obj != null && (obj instanceof Class) && ((Class) obj).isEnum()) { + final String enumClassName = ((Class) obj).getName(); + return getEnumModels().get(enumClassName); + } + return super.wrap(obj); } /** * Checks the ModelFactory instances registered in FreemarkerConfig, then * the default ones. If no appropriate ModelFactory was found, delegates to - * Freemarker's implementation. These factories are cached by Freemarker, - * so this method only gets called once per type of object. + * Freemarker's implementation. This is called by {@link freemarker.ext.beans.BeansModelCache}, + * which is itself called by {@link freemarker.ext.beans.BeansWrapper#wrap}. + * These factories are cached by Freemarker, so this method only gets called + * once per type of object. * * @see #DEFAULT_MODEL_FACTORIES * @see info.magnolia.freemarker.FreemarkerConfig