Hi,
You can refer my blog post -
http://www.ravindrarathore.com/blog/2019/03/14/adding-a-start-page-episerver-for-beginners.html
I will just jump in, trying to answer some of your questions.
- Q: Where is <head> defined?
- A: \Alloy\Views\Shared\Layouts\_Root.cshtml
- Q: Where is it defines that the _Root.cshtml mentioned above is used?
- A: \Alloy\Views\_viewstart.cshtml
- Q: How can I define that my page should use a different root view (or no root view)?
- A: Add a _viewstart.cshtml to the folder, or simply set the Layout in your view (in the same way as in _viewstart.cshtml).
- Q: Controller for "Standard Page" etc?
- A: The comment for DefaultPageController says: "Concrete controller that handles all page types that don't have their own specific controllers". Set a breakpoint to verify.
It's not that complicated, to create a new page type.
New page type definition, can also be used as the model:
using EPiServer.Core;
namespace Alloy.Models.Pages
{
[SiteContentType(GUID = "F336C153-137B-4D55-AD95-5F5BB3F7CEFC")]
public class NewPage : SitePageData
{
public virtual ContentArea MyContentArea { get; set; }
}
}
And then, your view, placed in \Alloy\Views\NewPage\Index.cshtml
@model PageViewModel<NewPage>
@Html.PropertyFor(x => x.CurrentPage.MyContentArea)
Then, that's it! You have a start, and can work from there...
Unfortuatnely, there seem to be no tutorials for creating hello world pages and blocks.
I have now figured out how to create blocks, with their optional models and partial views by copying "contentBlock" form Alloy.
The next problem is how to create a new page, with its own templates etc.
E.g. if I just wanted to output this:
I have a block which can render a message. Now I need a page to put the blocks on.
So I would guess I need some or all of the following:
1) a page template view. This is the thing which will have something like:
2) a page controller. This will do nothing except render the index action.
3) a page model. This will contain a single content area.
4) anything else?
The next problem is where to put the above files, and what they should contain.
If we look at alloys simplest page, "contact us". it is of type "standard page"
Searching for how standard page was implemented, we see a view in
/Views/StandardPage/index.cshtml
This is a start. It contains only the body part - the Heading, nav and content. Where is the outer part defined? the <head> for example?
Under Models/Pages we have
This is pretty straight forward, it defines two properites,t he main body and the content Area. The other pages properties are defined in SitePageData.
So thats the models covered I think.
Controllers
Under /Controllers we can see some block controllers, which is odd as most blocks wont have controllers, but I cant see a page controller for "Contact us" nor for "SitePageData" nor "Standard Page". could it be using "DefaultPageController"?
Default page controller looks like this:
This in herits from PageControllerBase, which has the login stuff and a strange section "modifyLAout" which just hides the header and footer, for no apparent reason.
Next we need to figure out how to create the most basic of views for a new page:
Views
As we noted, /Views/StandardPage/index.cshtml is missing most of the markup.
There is no "DefaultPage" nor "BasePage", so where is this defined? Where is the overall master tempage which renders most of the html?
By searcing all files, I found Views/Shared/Layouts/_Root.cshtml.
Where is this defined? how can I define that my page should use a different root view (or no root view if I want to hard code it in my page).