The layout is a first window or entry point for the page, For creating any page it's recommended to define one layout.
- This is an outer and first part of the HTML.
- Most of the structure related items should be there like Head section.
- One page one layout but for preview purpose, multiple preview version can be configured.
- Options available for WebForms (.aspx) and MVC (.cshtml)
This is like a master page in the web form application and in MVC it's like Views\Shared\Site.master
Sitecore location for the layouts-
Create your first layout for the site, Here you need to consider your information architecture, We are considering all possible scenario like multisites, custom components, and custom layouts.
First, create a folder for your main site and consider multisite setup
There are two options to define your layouts - one for web form based layout and second for MVC, We will be using here MVC layout.
Now create a folder for the Main site, site1 and site 2 then define MVC layout for the Main site.
Let's give it a name - HomeLayout
Select the location of the layout.
#SitecorePoint - Here we have to choose the location, Although we clicked on the selected folder, on this screen, Ideally it should default provider selection for the selected folder, instead of developer choose this item or location again.
Ok, Let's move forward.
Now at this position, we have to define where in the code/solution we want to save this layout.
Tip# Make sure our project structure and this structure should be the same to avoid the problem later.
If your project folder structure is different with the above path then please update the location here,
We have created below folder structure in the project solution, So we must need to update the path.
Update the path in the Sitecore and this will look like this
Publish the site, After the publish verify the location of deployed layout
Verify to the Sitecore virtual directory that this page has been moved there or not?
it should look like below
- Sub part of the main layout and parent of components.
- This is only applicable for web forms.
- Multiple sub layouts can be created within the placeholder.
- It's like dot net user control - .ascx available for WebForms (.aspx) and MVC (.cshtml)
Note:- As this is only compatible with Webform hence we are not using this anymore
This is the main section where actual site content will be rendered, there are several options within the rendering.
Controller rendering - This rendering will be based on controller and action name, in short, it will call a call file and that will run some logic or may invoke view itself.
View rendering - .chstml file can be directly plugin and can be executed.
Let's create some folder structure for the sample rendering.
Available options for the renderings.
- XSL Rendering - This is one of the oldest rendering in Sitecore, I rember in past this was using to render the items through XSLT, it's required a good understanding of XSLT to render the items.
- WebControl - Mostly used for the web form - We will not be using here.
- Method Rendering -Will discuss this in advance topic.
- URL Rendering - Will discuss this in advance topic.
- Controller Rendering - Controller can be defined and used here.
- Item Rendering - Will discuss this in advance topic.
- View Rendering - MVC view can be use here to render the view.