Grails Include template from external location -


how include external gsps or template in gsp file when template included not under views folder?

yes, can that. here go:

import grails.gsp.pagerenderer  class mylib {      static namespace = "foo"     static defaultencodeas = "raw"      pagerenderer groovypagerenderer      def externaltemplate = { attrs, body ->         string externalfilepath = attrs.externalpath          /*          * put content of external template file inside grails-app/views folder          * temporary unique name appended current timestamp          */         string temporaryfilename = "_external-" + system.currenttimemillis() + ".gsp"          file temporaryfile = new file("./grails-app/views/temp/$temporaryfilename")          /*          * copy content of external file path temporary file in views folder.          * required since groovypagerenderer can compile gsp located inside          * views folder.          */         temporaryfile.text << new file(externalfilepath).text          /*          * compile content of external gsp code , render          */         out << groovypagerenderer.render([template: "/temp/$temporaryfilename", model: attrs.model])          // delete file         temporaryfile.delete()     } } 

now in actual gsp want include external gsp, can write so:

<body>     <foo:externaltemplate externalpath="/home/user/anyexternalfile.gsp" model="${[status: 1}" /> </body> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -