Wednesday, October 1, 2008

Xtemplates Plugin Released

I've just released the Xtemplates Plugin in the Grails Plugins repository.

This Grails plugin increases the customization capabilities of the scaffolding templates. The default scaffolding templates are limited to generate list, create, edit and show views. With the xtemplates plugin you can generate any number of views. In the xtemplates generation process also a runtime loaded Helper class (which can be customized just like the templates) is binded so you can execute any code in the generation process.

I think both improvements would be a good candidate to be added to Grails core!

Just get started with installing the plugin:

grails install-plugin xtemplates

And then install the xtemplates:

grails install-xtemplates

The templates will be installed under \src\xtemplates\scaffolding
After changing the xtemplates you can use the following xgenerate commands:

grails uber-xgenerate
grails xgenerate-all
grails xgenerate-controller
grails xgenerate-views


Dale said...

Good stuff. This would be even better if you could use scaffolding to assume the modified Controller.groovy class. (i.e. - just use def scaffold = DomainClass). Or can you somehow?

I did get an error the first time trying this plugin though. What I did was create a new app, follow your instructions, create a simple domain class Person with one String field Name... then:

grails xgenerate-controller Person (error)

then I tried grails uber-xgenerate, and then got an error, then did the first command , and it worked. I don't have the error handy... what is "uber-xgenerate anyways"? A generate-all for all domain classes?

Marcel Overdijk said...


Do you still get the error? You might try to a grails clean.

uber-xgenerate indeed performs a xgenerate-all for all domain classes. Very handy ;-)

Dale said...

I did another test where I made 2 domain classes and did the uber right away no problems. And then one more test where I did the first testing scenario I described. No problems. So I'm guessing a clean would have fixed it too.

How about my idea about scaffolding? Would that be possible? I've been using Grails heavily over the last 8 months but haven't gotten into writing scripts or plugins yet, so I don't understand that part very well.

Marcel Overdijk said...

The plugin does not support dynamic scaffolding (def scaffold = DomainClass).

Anonymous said...

Just got a chance to dig into your plugin a bit.

I like the direction that you're taking things. Thanks for creating it.

I did a quick comparison of the actual templates (create/edit/show/list/etc) and it looks like for the most part those are just like in grails core.

The main difference (which I think is a big improvement) is the switch of using Helper.groovy (a real class file) over the renderEditor.template file (which is basically a big if statement and a bunch of groovy code in a gsp).

I've been thinking about doing some enhancements to the templating stuff myself. Letting the user config things about particular domain objects in the generated scaffolding.

Things like:

- omitting fields from edit/view
- picking particular fields that are used in the table in list.gsp
- auto adding a search field if searchable is installed and there is a searchable clause in the domain object
- better support of one-many and many-to-many relationships

These kinds of things could go a long way towards getting grails templates to be as usable as Django templates are.

Marcel Overdijk said...

Vote to add this functionality to Grails 1.1 at

Anonymous said...

Voted and watched! Thanks!