+1-888-365-2779
Try Now
More in this section

Forums / Project Feather / Access Parent Item In LIST View of Dynamic Widget

Access Parent Item In LIST View of Dynamic Widget

1 posts, 0 answered
  1. Jean
    Jean avatar
    0 posts
    Registered:
    04 Oct 2016
    04 Oct
    Link to this post

    Hi there, 

    I have built a custom module with a content-type hierarchy as follow: Locations >> Properties >> Rooms. I am in the process of making a custom template to list all the properties. My issue is that I for each property, I want to pull its associated Location (Parent Item) as well and I am at a loss for how to do this. I am pretty new to Sitefinity and Feather.

    I have looked at this: http://docs.sitefinity.com/feather-access-parent-or-child-items-in-dynamic-widget-views -- but it seems that is only for the detail view. Is there any way to pull the title of the parent item in the list view?

    Here is my code:

     

    @model Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Models.DynamicContentListViewModel
     
    @using Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Helpers;
    @using Telerik.Sitefinity.Frontend.DynamicContent.WidgetTemplates.Fields.Helpers;
    @using Telerik.Sitefinity;
    @using Telerik.Sitefinity.Data.ContentLinks;
    @using Telerik.Sitefinity.Frontend.Mvc.Helpers;
    @using Telerik.Sitefinity.Frontend.Mvc.Models;
    @using Telerik.Sitefinity.Web.DataResolving;
    @using Telerik.Sitefinity.Model.ContentLinks;
    @using Telerik.Sitefinity.Modules.Pages;
    @using Telerik.Sitefinity.Pages.Model;
    @using Telerik.Sitefinity.Model;
    @using Telerik.Sitefinity.Libraries.Model;
    @using Telerik.Sitefinity.Localization;
     
    @Html.Script(ScriptRef.JQuery, "top", false)
     
     
    <div class="@Model.CssClass row">
        @foreach (var item in Model.Items)
        {
     
            var navigateUrl = HyperLinkHelpers.GetDetailPageUrl(item, ViewBag.DetailsPageId, ViewBag.OpenInSamePage, Model.UrlKeyPrefix);
            <div @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid)item.Fields.Id) class="col-lg-12 hotels">
                <div class="col-lg-3">
                    @foreach (var relatedItem in item.Fields.BackgroundImage)
                    {
                        <a href="@navigateUrl">
                            <img src="@relatedItem.Fields.MediaUrl" alt="@relatedItem.Fields.Title" class="img-responsive hotelBg" style="height:100px;" />
                        </a>
                    }
                </div>
                <div class="col-lg-3">
                    <h3>@item.Fields.Title</h3>
                </div>
                 
                @foreach (var hotel in item.ParentItem("Location"))
                {
                    @hotel.Fields.Title
                }
     
                <div class="col-lg-2">
                    @if (item.Fields.Grade.ToString() == "5.0")
                    {
                        <img src="~/img/Rating Icons/5-stars_grey.png" class="img-responsive" />
                    }
                    else if (item.Fields.Grade.ToString() == "4.0")
                    {
                        <img src="~/img/Rating Icons/4-stars_grey.png" class="img-responsive" />
                    }
                    else
                    {
                        <img src="~/img/Rating Icons/3-stars_grey.png" class="img-responsive" />
                    }
                </div>
                <div class="col-lg-2">
                    <label>From: </label><h3>R2500.00</h3>
                    <span>Hotel Room</span>
                </div>
                <div class="col-lg-2 hotelButton">
                    <a class="btn btn-default">Book Now</a>
                </div>
            </div>
     
        }
     
        @if (Model.ShowPager)
        {
            @Html.Action("Index", "ContentPager", new
       {
           currentPage = Model.CurrentPage,
           totalPagesCount = Model.TotalPagesCount.Value,
           redirectUrlTemplate = ViewBag.RedirectPageUrlTemplate
       })
        }
     
    </div>

1 posts, 0 answered