Skip to content

Freemarker support cannot handle mixed extension types (ftl, ftlx, ftlh) #889

@tfield

Description

@tfield

Expected Behavior

Freemarker supports several extension types, ftl, ftlx, and ftlh. The x and h variants activate automatic escaping for xml and html respectively.

While it is possible to change the default extension for Freemarker, it is not possible to dispatch to a view that is anything other than the default. Developers should be free to choose .ftl, .ftlx, or .ftlh as the view from within controllers, on a case-by-case basis.

Actual Behaviour

Extensions other than the default extension are not found, returning a view not found error.

This appears to be due to the viewLocation method of FreemarkerViewsRenderer always normalizing the extension to the default value.

Note:

  1. It is possible to change the default extension via configuration, which allows controllers to dispatch to a different format, but this is a global change
  2. It is possible to <#include> a view of a non-default type - this does work as expected.

Steps To Reproduce

  1. create a new project and include micronaut views and freemarker
  2. create a freemarker view template that has the extension .ftlh
  3. attempt to render the view - fail

Changing the default

  1. configure the micronaut.views.freemarker.default-extension to be ftlh in application.yml
  2. attempt to render the view created above - success
  3. create another route and ftl tmplate as its view
  4. attempt to render the route with the .ftl view - failure

Environment Information

  • macos 14.6 on m1max
  • micronaut 4.4
  • micronaut views
  • freemarker

Example Application

No response

Version

4.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions