I would like to share content (essentially blocks of html) between templates.
For example, suppose I have a common footer section with a graphic or two, text and links to 'about us', 'contact us' and so on.
I have different templates for different page layouts, but they all require this footer.
So far I can think of three ways :
Nesting templates : ie have a master one which has the footer content, then a child one for each layout, then the actual page template, but this could get tricky if some pages need a different footer
Using a Partial View to hold the footer content and using #Html.Partial() to pull in the partial view on the various templates
Create a settings document with the footer content and use Umbraco.Content() to fetch the footer property
Is any of these the recommended process (and are there any pitfalls?) or is there a better way?
I would normally do one of the following:
Have properties on the homepage for the footer links etc (in a separate tab) and pull in the values into the footer partial, this way you only have to set it once, rather than having it on every page
Have a Site Settings node at the same level as the home page and pull the values from there into the footer partial
That seems to be fairly standard from most of the Umbraco sites that I've worked on. I wouldn't have all of the properties on each page, unless you need a unique footer each page for some reason.
For example, lets say you add a tab called "Footer Settings" to the Home Page DocType with a single string property with the alias "copyRightNotice" and then you want to display that in a partial, your partial might look something like:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
var rootPage = Model.Content.AncestorOrSelf(1);
<h3>#rootPage.GetPropertyValue("copyRightNotice")</h3>
}
Related
I'm developing a ASP.NET MVC5 razor project and I have a cshtml divided into two parts, left part has a div with a treeview with options like a menu and the right part is a div that I would like to load cshtml that correspond to the option selected in treeview, ¿how can I do to achieve this?
Thanks
I am making the assumption that this is a simple navigation that is consistent amongst all pages, for which you can put the common navigation in the _Layout.cshtml. This file contains all the common , , tags used for each page. If you put your navigation in here then it will also be displayed on each page.
The navigation options can then link to your normal actions which display the corresponding views within the layout page.
In this tutorial the author discusses adding a simple navigation (in the section "Using a Layout for common site elements") in the _Layout with the difference that the navigation is at the top and not at the side. You can use css to style the page differently.
I new to Ruby on Rails, and I am coming from Drupal/PHP background.
I am trying to do something simple. A "Static" controller for some pages like about us, disclaimer etc. and a "Video" controller for videos.
The whole application has same look. I am trying to figure out how I can avoid duplicating views.
In drupal the theming goes like this:
html.tpl.php (renders page.tpl.php)
- page.tpl.php (renders multiple block.tpl.php)
- block.tpl.php (renders more nested tpls or some html generated by theme functions).
I find this to be great.
In rails, what I read is there is application.html.erb (Which I think is similar to html.tpl.php of Drupal, as it normally contains stylesheets, js, etc. available throughout the application) called "Layout". Then there are "Views", which "yield" content in this layout. We specify the view in controller, or it gets one automatically. I think of a view as "page.tpl.php" of Drupal.
Most of my site uses same structure i.e. header, top menu, content, right sidebar, footer. But content of each area changes depending on the path. So I am thinking of doing it like this:
Both 'Static' & 'Video' will call the same view, with different variable values i.e. values for content area and sidebar.
This View will the use 'render' to render another view, with a subset of variables passed from controller i.e. it will render content & sidebar views.
If needed, those views will render more views, and so on.
Another one I read about is partials. I can't seem to differentiate between rendering a view inside another view, and rendering a partial.
Which method is better? Or is there a better "Rails Way"?
This is quite a large topic to cover but edited highlights are
If you want to repeat content on every page, like a header or navbar for example then put it in layouts/application.html.erb
if you want to keep your views tidy with content specific to that page then you can use partials. Normally in views I create a folder called shared and then put my partials in there. for example if i save a partial called _form.html.erb (make sure you name partials with the underscore at the beginning of the file name), i would then call that in my view like
<%= render 'shared/form' %>
you can also use partials in the layouts/application file to keep that clean aswell
This is just my way of doing it, I'm sure more experienced rails guys have better ways
Hope that helps, any more questions then just ask
In my ASP.NET MVC 3 project I have a master layout with a section defined. This section is responsible for displaying content in a sidebar, when it has any content assigned to it.
The problem I've encountered is the following:
I have some edit views, where both the sidebar and the main area is used for editing data. In this case the sidebar and the main body should be wrapped into one single form with a single submit button.
What is the best solution for this? The solution I came up with is that when the functionality I mentioned is necessary, I set a boolean property in my ViewBag. If this property is true, the master layout is rendered with the sidebar and the main content area wrapped in a form.
Is there a better way to this? The solution I described is a bit 'hackish' for me.
I would have two layouts. One with a seperate side-bar, and one without. Then, in the pages you need a sidebar with editable fields, you include the sidebar in your content page, not in the master.
The boolean you are using in the ViewBag can be better represented in the Model for the view of the master page. You can then include the side bar using a partial view. It would look somehting like this...
master.cshtml:
#using (Html.BeginForm("ActionName", "Controller", "POST")){
//
// Master form elements go here
//
//Side bar
#if(Model.ShowSideBar){
#Html.Partial("MySideBarPartialView" [, Model.SideBarModel ] )
#}
#}
You model (if any) should have a property that is set with the model for the side bar.
I am working on a help page which is composed of a navigation tree, content box, and search box. The navigation tree has links to Frequently Asked Questions and Glossary, each of which are linked to an Action which return partial views.
To the right of the navigation tree I have a single content div that I would like to contain whichever partial view is selected in the navigation tree.
Success case (what I want to accomplish): clicking on one of the FAQ links calls the FAQ() method in my controller, then returns a partial view which is then displayed in my content div to the right of the navigation tree. Clicking on another item would cause another partial view to be loaded.
How do I go about this? I've read a ton of ASP.NET MVC JQuery loading blog posts and tutorials but can't find anyone who's done exactly this.
Many thanks!
You should be able to use the jQuery method .load() to load HTML into your div.
http://api.jquery.com/load/
You can create an action that returns the partial view as HTML.
ASP.NET MVC Returning Partial View as a full View Page
jQuery:
one easy way you can do is load all partial views in "Container Div" at page load in one go (if performance is not a issue)
then assign each partial div with different div id inside "container", than use jquery to control show(); hide(); for each div.
MVC:
however if i were you, "Glossary" and "FAQ" looks same model to me it shouldn't be put in different partial view in first place.
if they did designed in separate model, in this scenario, i would recommend you to create a proxy class as a ViewModel above models you want to display, and then load it with one partial view only
What would be the best way to implement visual inheritance for partial ascx views in MVC?
I have the main Site.Master file which provides a header, footer, sidebar and main content area. Then i have an Info.Master which uses Site.Master as it's master page and which provides a common layout for almost identical pages. Then all these similar "info" pages on the site have Info.Master set as their master page.
Now i would like to do the same for the ascx partial views that appear on the side bar, as I have a handful of controls that all "look" the same, with headers, footers etc?
You could use normal ASPX views as partials, and create another master page for them with your common partial layout elements. Check out this post from Jeffrey Palermo for more information on this technique.
Another option would be to put your common partial layout elements in one of your main master pages, and take advantage of the view locations. For example, if you had a partial called "Sidebar" with content that only changes for each controller, you could create a general partial in the Views/Shared directory, and more specific partials in each Views/<controller name> directory, and the partial will be overridden.
<div id="sidebarheader">...</div>
<% Html.RenderPartial("Sidebar"); %>
<div id="sidebarfooter">...</div>