Skip to content

Commit

Permalink
Add ability to define base path for Freemarker templates
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Jun 9, 2023
1 parent 5b0f3e3 commit eec9eb9
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ public class FreemarkerContext implements Context<Configuration> {

private final Configuration configuration;

/**
* Creates a default context that stores Freemarker configuration.
*/
public FreemarkerContext() {
this(BASE_PACKAGE_PATH);
}

/**
* Creates a new context that stores Freemarker configuration.
*
* @param basePackagePath The package that contains the templates, in path ({@code /}-separated) format. Note that
* path components should be separated by forward slashes independently of the separator
* character used by the underlying operating system. This parameter can't be {@code null}.
*/
public FreemarkerContext(String basePackagePath) {
this.configuration = new Configuration(Configuration.VERSION_2_3_23);
this.configuration.setLocalizedLookup(false);
this.configuration.setTemplateUpdateDelayMilliseconds(0);
this.configuration.setClassLoaderForTemplateLoading(getClass().getClassLoader(), BASE_PACKAGE_PATH);
this.configuration.setClassLoaderForTemplateLoading(getClass().getClassLoader(), basePackagePath);
}

@Override
Expand Down

0 comments on commit eec9eb9

Please sign in to comment.