Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:15:31+00:00 2026-06-18T09:15:31+00:00

I am working on a Grails site which although it needs to include a

  • 0

I am working on a Grails site which although it needs to include a deal of CMS-like functionality is yet not (for various reasons) being built as part of an actual CMS installation. One thing that I need to allow the user to do is to edit the HTML layout — which, in a Grails application, is laid out in a GSP file — and other normally-static elements of the different pages, which will neither be tied to any specific domain object nor form any part of one of the CRUD pages which deal with domain objects.

I know both that it is possible to specify the views directory and that it is possible to write, from within the app somewhere, to actual files in the running app. I know further that it might require a great enormous deal of care, if I were to do this, to be sure that the user does not too badly destroy the entire layout and content of the page, and I am prepared to deal with that. But is it possible to allow user editing of the layouts and other GSP files used to create a Grails page? If so, how might I go about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:15:33+00:00Added an answer on June 18, 2026 at 9:15 am

    If you store the template/layout in the database (as some have suggested above) you can
    render it using the GroovyPagesTemplateEngine:

    package com.mycompany
    
    import groovy.text.Template;
    import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine 
    
    class TemplatingService {
      GroovyPagesTemplateEngine groovyPagesTemplateEngine
    
      def render(String templateString, Map model) {
        ByteArrayInputStream bais = new ByteArrayInputStream(templateString.getBytes());
        Template template = groovyPagesTemplateEngine.createTemplate(bais)
    
        try {
          def writer = new StringWriter()
          template.make(model).writeTo(writer)
          return writer.toString()
        } catch (Exception e) {
          // handle exception
          return ""    // or "[an error occurred]" or rethrow the exception
        }
      }
    }
    

    Now, while you CAN do this, please be sure to think of the implications. Anything you could execute in a gsp can be executed in this context. Like writing to, or deleting files, executing commands, etc.

    I never figured out how to leverage a SecurityManager to limit what could be done in the templates, so my solution was to not allow users to enter templates into the database. If I want a new template, I put it there myself, after checking it for security implications.

    You can also improve performance by caching the results of createTemplate() to avoid recompiling it each time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web application (using Grails) which will generate a gift
I am working on my first Grails application, which involves porting over an old
I am currently working on a Grails project and would like to know the
I am working on a grails application which uses Amazon's SimpleDB. I changed a
I'm working on a Grails 2 app, which has HTML 5 based scaffolding. For
I am new to Grails and working on a project which has just 2
I am working with Grails 2.1.1 and would like to add a handful of
I am working on a super sweet Grails project. I get simple tests, like
I am currently working on grails project. I have created eight different plugins. Each
I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.