The "grails install-templates" is not available in Grails 3 any more. I was wondering what is the alternative command for this? How can I customize scaffolding templates in Grails 3? Thanks.
The command grails install-templates should actually work.
According to the docs it copies the templates of all code generation activities to the application's src/main/templates/scaffolding directory.
I have tried it and it works. Be aware that the customised scaffolding will work only for files generated with grails generate-all command and not for views which are generated dynamically in with the controller's scaffold = true property.
Related
I have developed a project using grails 2.4.4 and so happy with the automation generation code tool by command : grails install-templates and grails generate-all com.domain.DomainClass.
The problem when I update to version 3.0 is that customizing template style is really hard, I spent whole day to learn but now decide to give up . Version 3.0 uses the field plugin org.grails.plugins:fields:2.1.5. :(
In version 2.4.4, I customized and changed the default template in my own, and it worked well with my css style.
My question is that can I use my old template for 3.0 grails project. I tried by it throws error at runtime.
Its quite easier to customize as well in Grails 3. Go to your scaffolding template directory
your_project\src\main\templates\scaffolding
You can see there create.gsp edit.gsp index.gsp show.gsp.
Just use your own CSS class there and then generate scaffolding. You will get your desired style in your next view files.
Is it possible to customize grails-plugin-fields templates to override default f:table and f:all templates?
I've tried placing a custom _table.gsp file inside my application grails-app/views/templates/_fields/ and src/main/templates/_fields/ but it doesn't works.
From the plugin source code seems that this is the right place to create this file.
I had the same problem with you. I worked it out by placing _table.gsp in /grails-app/views/templates/_fields/. I tried to place it in /src/templates/_fields/ but didn't work. Here's the proof.
I'm using grails 3.0.7 and testing this by using grails run-app command, by the way.
Cheers!
I created some templates for the auto-generation code by grails install-templates, but some unnecessary files like form.gsp are still created. How can I remove them? I cannot find a config file to modify and create only my templates. Can anyone help me?
grails install-templates installs a copy of the Grails templates to src/templates for you to modify. If you don't care about form.gsp, then just ignore it. The templates aren't packaged into your WAR, they are simply used by the Grails generate-* commands. If you feel it's necessary to remove it, just don't run grails install-templates again. The command only needs to be done once.
Grails builds up the list of templates that it needs to generate from by combining the default set of templates in GRAILS_HOME with the ones installed in your app, with the one in your app taking precedence in the case of a name clash. So if you delete a template from your app's src/templates then Grails will simply use the built-in version of that template instead. I presume this is deliberate don't-repeat-yourself behaviour, to allow you to selectively override some of the templates but stick with the defaults for others without having to have a duplicate copy of the ones you haven't modified.
So I don't think you can prevent the form.gsp from being created when you generate-views, but if your modified scaffolding templates don't reference it then it does no harm being there and you can just ignore it. You could create an empty version in your src/templates
<%-- This file intentionally left blank --%>
When you execute the command "grails install-templates" it generates a folder src/templates/scaffolding. Inside this folder are the files that will be generated automatically when you execute o comando generete-all/view/controller.
I'm using Grails 1.37 with Netbeans. When I generate the scaffolding how do I only generate the form in the GSP, not the grails logo etc?
Use grails generate-views yourpackage.yourDomainClass to generate the views only
Use grails generate-controller yourpackage.yourDomainClass to generate the controller with full crud actions
Use grails generate-all yourpackage.yourDomainClass to do the both commands above
If you want to customise the scaffold engine, take a look on the src/templates/scaffolding directory
May this help.
grails generate-view com.package.Domain
Is it possible to customize code generated from grails create view command? for example can I use YUI or JQuery UI library for view code generation? Is there any sample for that?
Thanks,
Running the Grails command grails install-templates will copy into src/templates the template files used by all of the other Grails commands to generate files. You can then modify them however you wish.
Also, you may wish to look at some of the scaffolding plugins, such as Grails Twitter Bootstrap Scaffolding or Enhanced Scaffolding.