Tutorial 4 - Entity information and making links
- Home /
- Tutorials /
- CMS tutorials /
- Tutorial 4 - Entity information and making links
In this tutorial we will show you how to retrieve information about an entity, such as its URL, as well as how we can access child items.
For this tutorial we will use content model from tutorial 2 that will represent content pages
[SystemName("ContentPage")]
[PublicPage("ContentPage", isSEO: true)]
[AdminMenu("DevCommerce/Content")]
[Parent("Content Management")]
[Icon("fa-book")]
[Localazible]
[IsSearchable]
public class ContentPageModel : DPPublicNavigationPageModel, IDPModel
{
[DPParent]
public ContentPageModel Parent { get; set; }
}
In this model we have used special property names Parent, when plugin will install the system will know that ContentPage entity can be added as a child to the ContentPage.
Let’s review ChildEntitiesNavigation action of DPPublicPage controler that allows to access child entities
public ActionResult ChildEntitiesNavigation(int entityId)
{
var childEntities = _entityService.SearchEntities(parentId: entityId);
var models = _entityModelService.GetModels(childEntities);
return View("_DP_ChildEntitiesNavigation", models);
}
We can now use our model to easily render out the left navigation in _DP_ChildEntitiesNavigation view, notice how we can use the UrlRecord property in the links href:
@model List<DevPartner.Nop.Plugin.Core.Models.CMS.DPPublicPageModel> @if (Model.Count > 0) { <div class="block block-entities-navigation"> <div class="title"> <strong>@T("Categories")</strong> </div> <div class="listbox"> <ul class="list"> @foreach (var entity in Model) { <li> <a href="@Url.RouteUrl("Entity", new { SeName = entity.UrlRecord })">@entity.Name</a> </li> } </ul> </div> </div> }
Now you can add the following string to use in your public page view
@Html.Action("ChildEntitiesNavigation", "DPPublicPage", new { entityId = Model.Id })
With this added to your content page view you should be able see a list of links to each of the child pages.
In this tutorial we have seen how we can get the information about an entity and how we can easily traverse to the child entities of a particular entity.