generic view url mapping in grails

814 views Asked by At

I'm trying to do this:

"/templates/$tml"{
        view: "/templates/$tml"
    }

and this:

"/templates/$tml"{
        view: "/templates/${tml}"
    }

and this:

"/templates/$tml"{
        view: "/templates/${params.tml}"
    }

But none of them work. In the template folder I have a a lot of GSP files and I don't want to map them one by one, instead I want some generic code which map them like the controller mapping.

Thanks for help!

2

There are 2 answers

1
user711189 On BEST ANSWER

Did you try something like this?

In the UrlMappings.groovy:

"/templates/$tml"(controller: "templates", action: "generateView")

In the TemplatesController.groovy:

def generateView(String tml){
    render(view: tml)
}
1
Suganthan Madhavan Pillai On

I am not sure but you can try something like this

"/templates/$tml"(view: "/templates/$tml")

Normal procedure is

"/templates/$tml"{
    controller = "general"
    action = "generalAction"
    //pageName = "yourpage"
 }