Grails render page inside other - grails

I have a gsp page with a form that I would like to put inside a div in another gsp page. Each gsp page have diferent css configuration for 'body'. Is it possible to that that using in Grails (like render).

Yes. In fact it's pretty simple. Best, extract the "common" part into a separate template (.gsp) file and include it into both pages.
See render for more information.

Related

What does the term "template" mean?

I am learning Rails 5.0, via a tutorial. Learning how to generate view templates, but the term "template" is never explicitly defined. I've searched in the Rails docs, and they seem to mention the word a lot, but also never really define it explicitly.
I know that views are the HTML, CSS associated with what the user sees. But was wondering what is a template and how is it different than a standard webpage?
I don't have an authoritative answer. But this is really rather simple. RoR lets you generate content dynamically. This means, with one template, you could generate different content (html pages). The final html page generated and served by the server is the webpage endusers see. For example, you could have a template show.html.erb with the following line:
<h> Product <%=#product.name%> </h>
From this template, different webpages for each different #product can be generated with that #product's name, depending on the #product variable, which is provided by the controller.
So templates allow you to dynamically generate content and render them as different html webpages.

Umbraco Dashboards: custom markup within tabs and specific content page

In my tab from home page I want to render a partial view returned by an action controller, with custom css. The home page has its own doctype. Using Umbraco v7.
How can I achieve this? I read http://our.umbraco.org/wiki/reference/files-and-folders/dashboardconfig but doesn't specify this.
You can only load a usercontrol (ASCX) in the dashboards.
But that shouldn't stop you from what you want to do.
Put your Html and css in the ASCX and
put your controller code in the .cs file.
update the /config/dashboard.config
And you are set.
What you could do is wrap your partial view in a macro and call the macro inside the ascx (<umbraco:Macro alias="theMacroAlias" runat="server" />)
Update: you can't set a dashboard for a specific content page. The only way to archive something here is to create your down propertyType

how do i dynamically change my format rendering engine in rails?

My default templating engine is haml, but I would to sometimes change it to erb if i specify a specific parameter?
For example, I am pasting in some html code and would just like to test the code without HAML complaining about its format.
Any idea how to do this?
do something like:
if params[:render_erb]
render 'file.html.erb'
else
render 'file.html.haml'
end
and call the action with ?render_erb=true
or
render "file.html.#{params[:render]}" ir params[:render]
and call it ?render=haml or ?render=erb (or nothing and it will use the default
at the end of the controller's action that you are using
Am I wrong that you simply need to save file as your_file.html.erb instead of your_file.html.haml?
You can use different templates in the same application, and you can use different template engines for views, partials, and layouts, but as far as I know you can't duck in and out of multiple template engines within the same template file.
If you just want to drop some code in using a different template language, then I'd put it in a separate partial. That certainly seems easiest in this particular case.

I can't get the grails controller "render" method to work with an explicit template

I'm just getting started with grails, and I'm having an issue.
I have a "controller" and "view" for the projects home page (there's no model for the home page)
I called the view "index.gsp", and put it in a directory views/home
However, no matter what I do, grails is trying to read the page "home.gsp" (and then home.jsp), despite me having explicitly specified the index with the "template" attribute in the render call.
class HomeController {
String someparameter = "xyzzy"
def index = {
render(view:"home", template:"index") // I also tried "index.gsp" and "home/index.gsp"
}
}
I think I may be using the "template" attribute wrong, because I only see it used in examples for view-less template rendering. However the documentation gives no such limitation.
Is there any way to explicitly specify the name of a template? I just caved in and renamed it "home.gsp", but I'd like to understand what's going wrong.
(The home page in this application has no "model". Grails will use the controller has the model. In this example, you can access "someparameter" in the gsp template as ${someparameter}.)
I think you may be misunderstanding what a Grails template is. Think of a template as a reusable fragment. A template is a GSP that starts with an underscore like _menu.gsp that you would typically render from within another GSP with the a tag like <g:render template="menu"/>.
It doesn't make sense to render both a view and a template at the same time. They are mutually exclusive at this point.
Are you looking to implement a Layout? If so, see the docs or the grails.org explaination.
Basically, your view you would have a <meta name="layout" content="main"> tag in the <head/> tag of your view -- which indicates that the view will be meshed together with the main layout located in grails-app/views/layouts/main.gsp

Rails include page

How would I include a page from the public folder in one of my views? I want to include a single header like I do in PHP so when I make a change it affects all the other pages. (It is for multiple views)
For the most part, the only web pages in the public folder will be purely static (custom 404 pages, FAQ, etc). If you have a piece of static HTML that you'd like to be displayed in a lot of pages, a partial is what you're looking for.
A partial doesn't have to be tied to a controller. You can create the sub-directory:
/views/static
and fill it with a whole bunch of partials, so you would have:
/views/static/_my_first_partial.html.erb
/views/static/_my_second_partial.html.erb
and anywhere you want those fragments, you can do:
render :partial => "static/my_first_partial"
and voila, you're done!
I'm pretty new to rails, but I guess for such task you would use Layouts:
Layouts and Rendering

Resources