Override grails g: link tag

I am trying to override the g: link tag so that I can prefix the extra line. Here is my code:

import org.codehaus.groovy.grails.plugins.web.taglib.*

class ApplicationTagLib {

    static namespace = "g"

    def link = { attrs, body ->
        if("es".equalsIgnoreCase(request.stLocale.language)) {
            attrs['controller'] = "es/" + attrs['controller']
        }
        def applicationTagLib = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
        applicationTagLib.link.call(attrs, body)
    }
}

This works fine except that when I add "es /", the resulting path is translated to es% 2F instead of es /, which is why the link doesn't work.

Is there a way to prevent the automatic encoding of a new slash, or is there a better way to prefix this string to the controller path?

+3
source share
2 answers

You should know that in Grails the controller package (thus, this location in the project structure path) does not correlate with the default URL display - the structure is smoothed.

, , , , URL- (, , ).

, .

+1

'/es' , Grails, UrlMappings.groovy. , grails create-app, '/es' URL- :

class UrlMappings {

    static mappings = {
        "/es/$controller/$action?/$id?" {  // <---------- added '/es' prefix
            constraints {
                // apply constraints here
            }
        }

        "/"(view: "/index")
        "500"(view: '/error')
    }
}

URL, . Grails.

+1

All Articles