When a new app is created, two views are main.html and index.html. main is never explicitly rendered, it is extended as
#{extends 'main.html' /}
How do I pass a variable to a view (main.html), when its only extended from another view (index.html)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
If it is passed to the render method, it will be available as per normal. The entire view, including extends and includes are rendered by the Groovy template engine.
However, in the case of the
main.htmlwhich is usually extended on every view, the best option is to always add it to therenderArgsmap using the@Beforeannotation, as follows. This ensure that it is always available, and you Do Not Repeat Yourself (DRY).This way, you don’t need to pass somekey into the render method on every render call.
Then, in your
main.html, you can accesssomekeysimply using the standard method of$somekey.