Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Cort Larsen 346 posts 797 karma points
    Jun 18, 2014 @ 21:44
    Peter Cort Larsen
    0

    vorto values inchildren loop

    HI , cant seem to get values in a loop.

    whats wrong with this?

     

    @using Our.Umbraco.Vorto.Extensions;
    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{
    var selection = CurrentPage.Nyhed.Where("Visible").OrderBy("date desc");
    }
    @if (selection.Any())
    {
    foreach (var page in selection)
    {
    <section class="group"> <img src="/images/justty/image3.jpg" class="alignleft" alt="image">
    <h3>
    <a href="@page.Url">
    @if (page.Content.HasVortoValue("bodyHeader"))
    {
    @Html.Raw(GlobalHelpers.TruncateAtWord(@page.Content.GetVortoValue("bodyHeader"), 25, true))
    }
    else
    {
    @Html.Raw(GlobalHelpers.TruncateAtWord(@page.Content.Name, 25, true))
    }
    </a></h3>
    @if (page.Content.HasVortoValue("bodyIntroText"))
    {
    <p>@Html.Raw(GlobalHelpers.TruncateAtWord(@page.Content.GetVortoValue("bodyIntroText"), 165, true))</p>
    }
    @if (page.HasValue("date"))
    {
    <div class="metadata"><small>@page.date.ToString("dddd d MMMM yyyy")</small></div>
    }
    </section>
    }
    }

  • Matt Brailsford 2246 posts 10979 karma points MVP 6x c-trib
    Jun 18, 2014 @ 22:21
    Matt Brailsford
    100

    Hi Peter,

    I see two issues from a Vorto perspective.

    1) You are using the dynamic CurrentPage property, rather than the strongly typed 'Model.Content' property. Unfortunately Vorto currently only supports the strongly typed version. You can do everything you can do with the dynamic property with the strongly typed methods, but it means you'll have to change how you get some properties like @page.date to be more like @(page.GetPropertyValue<DateTime>("date")) instead.

    2) Once you are using the strongly typed model, you shouldn't need to use.Content within the loop as page should already be of type IPublishedContent (you only need it in your standard view because the current pages IPublishedContent is accessible via a .Content property on @Model)

    It might be worth you taking a look at the docs regarding the difference between CurrentPage and Model.Content if you are not already familiar with this.

    http://our.umbraco.org/documentation/Reference/Templating/Mvc/views

    Hope this helps

    Matt

  • Peter Cort Larsen 346 posts 797 karma points
    Jun 18, 2014 @ 22:37
    Peter Cort Larsen
    0

    Hi,

    So i should get the children something like this? This fails thou, cant seem to find the way to do it from your link.

     var selection= Model.Content.Nyhed.Where("Visible").OrderBy("date desc");

  • Peter Cort Larsen 346 posts 797 karma points
    Jun 19, 2014 @ 10:03
    Peter Cort Larsen
    0

    Hi, after fiddling around, i got it to work. Thanks.

  • Matt Brailsford 2246 posts 10979 karma points MVP 6x c-trib
    Jun 19, 2014 @ 11:46
    Matt Brailsford
    0

    Nice work Peter.

    I think it's way more valuable to help a person discover the answer rather than to just give it outright, so well done on getting it working.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft