FreeMarker Plugin

FreeMarker plugin is not able to render views (ftl) within plugins

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Grails-FreeMarker 0.3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Hi.

Please, see this post:

http://grails.1312388.n4.nabble.com/freemarker-tags-rendering-plugin-loading-freemarker-views-in-a-plugin-and-rendering-as-pdf-td3665958.html

I have suggested this ugly (and hardcoded) workaround:

// resources.groovy
import grails.util.BuildSettingsHolder

// Place your Spring DSL code here
beans = {

boolean developmentMode = !application.warDeployed

freemarkerConfig(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) {
if(developmentMode) {
templateLoaderPaths=["file:${BuildSettingsHolder.settings.baseDir.absolutePath}/grails-app/views".toString(), 'file:/home/daniel/.grails/1.3.7/projects/main-app/plugins/child-app-0.1/grails-app/views']
} else { templateLoaderPaths=['/WEB-INF/grails-app/views', '/WEB-INF/plugins/child-app-0.1/grails-app/views'] }
}

}

But i think it can be done correctly in FreeMarker plugin.

Thanks.

Activity

Hide
Daniel Henrique Alves Lima added a comment -
import grails.util.BuildSettingsHolder

// Place your Spring DSL code here
beans = {

    boolean developmentMode = !application.warDeployed

    freemarkerConfig(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) {
        if(developmentMode) {
            templateLoaderPaths=["file:${BuildSettingsHolder.settings.baseDir.absolutePath}/grails-app/views".toString(), 'file:/home/daniel/.grails/1.3.7/projects/main-app/plugins/child-app-0.1/grails-app/views']
        } else {
            templateLoaderPaths=['/WEB-INF/grails-app/views', '/WEB-INF/plugins/child-app-0.1/grails-app/views']
        }
    }

}
Show
Daniel Henrique Alves Lima added a comment -
import grails.util.BuildSettingsHolder

// Place your Spring DSL code here
beans = {

    boolean developmentMode = !application.warDeployed

    freemarkerConfig(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) {
        if(developmentMode) {
            templateLoaderPaths=["file:${BuildSettingsHolder.settings.baseDir.absolutePath}/grails-app/views".toString(), 'file:/home/daniel/.grails/1.3.7/projects/main-app/plugins/child-app-0.1/grails-app/views']
        } else {
            templateLoaderPaths=['/WEB-INF/grails-app/views', '/WEB-INF/plugins/child-app-0.1/grails-app/views']
        }
    }

}
Hide
Daniel Henrique Alves Lima added a comment -

BTW, sitemesh template will be applied to views in the plugin. I've forgotten the meta header (<meta name="layout" content="main" />).

Thanks.

Show
Daniel Henrique Alves Lima added a comment - BTW, sitemesh template will be applied to views in the plugin. I've forgotten the meta header (<meta name="layout" content="main" />). Thanks.
Hide
Daniel Henrique Alves Lima added a comment -

Another workaround:

import grails.util.BuildSettingsHolder

// Place your Spring DSL code here
beans = {
        boolean developmentMode = !application.warDeployed
        
        
        List paths = []
        
        for (plugin in manager.getAllPlugins()) {
            paths << plugin.pluginPath
        }
        
        String viewsDir = '/grails-app/views'
        if(developmentMode) {
            List newPaths = []
            //for (pluginBaseDir in BuildSettingsHolder.settings.pluginBaseDirectories) {
            for (pluginBaseDir in [BuildSettingsHolder.settings.pluginBaseDirectories[0]]) {
                if (pluginBaseDir.endsWith('/plugins')) {pluginBaseDir = pluginBaseDir.substring(0, pluginBaseDir.length() - '/plugins'.length())}
                for (path in paths) {
                    newPaths << "file:${pluginBaseDir}${path}${viewsDir}".toString()
                }
            }
            paths.clear()
            paths.add("file:${BuildSettingsHolder.settings.baseDir.absolutePath}${viewsDir}".toString())
            paths.addAll(newPaths)
        } else {
            paths.add(0, '')
            paths = paths.collect {path -> "/WEB-INF${path}${viewsDir}".toString()}
        }

        //println "paths ${paths}"
        
        freemarkerConfig(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) {
            templateLoaderPaths = paths
        }
}
Show
Daniel Henrique Alves Lima added a comment - Another workaround:
import grails.util.BuildSettingsHolder

// Place your Spring DSL code here
beans = {
        boolean developmentMode = !application.warDeployed
        
        
        List paths = []
        
        for (plugin in manager.getAllPlugins()) {
            paths << plugin.pluginPath
        }
        
        String viewsDir = '/grails-app/views'
        if(developmentMode) {
            List newPaths = []
            //for (pluginBaseDir in BuildSettingsHolder.settings.pluginBaseDirectories) {
            for (pluginBaseDir in [BuildSettingsHolder.settings.pluginBaseDirectories[0]]) {
                if (pluginBaseDir.endsWith('/plugins')) {pluginBaseDir = pluginBaseDir.substring(0, pluginBaseDir.length() - '/plugins'.length())}
                for (path in paths) {
                    newPaths << "file:${pluginBaseDir}${path}${viewsDir}".toString()
                }
            }
            paths.clear()
            paths.add("file:${BuildSettingsHolder.settings.baseDir.absolutePath}${viewsDir}".toString())
            paths.addAll(newPaths)
        } else {
            paths.add(0, '')
            paths = paths.collect {path -> "/WEB-INF${path}${viewsDir}".toString()}
        }

        //println "paths ${paths}"
        
        freemarkerConfig(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) {
            templateLoaderPaths = paths
        }
}
Hide
Daniel Henrique Alves Lima added a comment -
Show
Daniel Henrique Alves Lima added a comment - This bug can be closed: https://github.com/grails-plugins/grails-freemarker/pull/3 Thanks.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: