Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 583 posts 1407 karma points
    Aug 30, 2014 @ 18:20
    Sebastian Dammark
    0

    How to render Archetype with Razor ?

    I have a page with 3 Archetype properties and I've found this piece of Razor on the forum:

    @{
    var desktop = CurrentPage.Content.GetPropertyValue<ArchetypeModel>("desktop_archetype")
    var tablet = CurrentPage.Content.GetPropertyValue<ArchetypeModel>("tablet_archetype") var handheld = CurrentPage.Content.GetPropertyValue<ArchetypeModel>("handheld_archetype")
             foreach (var fieldset in desktop) { if (fieldset.Equals(slider.First())) { <p>True</p> } else { <p>False</p> } } }

    But it keeps failing on me with this message:

    The type or namespace name 'ArchetypeModel' could not be found (are you missing a using directive or an assembly reference?)

    I'm doing this in a regular template which has this line in the top.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage 

    And I've tried to use CurrentPage and Model but with no luck whatsoever.

    I know I'm new at this, but what am I doing wrong ?

  • Yakov Lebski 591 posts 2347 karma points
    Aug 30, 2014 @ 18:29
    Yakov Lebski
    0

    using Archetype.Models;

    I'm using the latest version of Archetype.

    My code looks : Model.Content.GetPropertyValue

  • Sebastian Dammark 583 posts 1407 karma points
    Aug 30, 2014 @ 20:11
    Sebastian Dammark
    0

    Thanx, now it doesn't fail :)

    But it's like it doesn't see any fieldsets

    @{
    var desktop = CurrentPage.Content.GetPropertyValue("desktop_archetype");
    
    if (desktop.Fieldsets.Any()) {
    <p>Fieldsets</p>
    } else {
    <p>No fieldsets</p>
    }
    }

    This return "No fieldsets"

  • Yakov Lebski 591 posts 2347 karma points
    Aug 30, 2014 @ 21:12
    Yakov Lebski
    0

    What version of Archetype you are using?

  • Sebastian Dammark 583 posts 1407 karma points
    Aug 30, 2014 @ 21:16
    Sebastian Dammark
    0

    I'm using 1.4.1

  • Yakov Lebski 591 posts 2347 karma points
    Aug 30, 2014 @ 21:19
    Yakov Lebski
    0

    Sorry I posted invalid code sample: Now is right part of code Model.Content.GetPropertyValue<Archetype.Models.ArchetypeModel>("PROPERTYNAME")

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 31, 2014 @ 04:21
    Bjarne Fyrstenborg
    0

    Hi Sebastian

    have you included the Extensions namespace? https://gist.github.com/kgiszewski/8863822

    @using Archetype.Models;
    @using Archetype.Extensions;

    An example:

    <div class="row">
    @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("featuredBoxes"))
    {
        Umbraco.Web.Models.DynamicPublishedContent media = Umbraco.Media(fieldset.GetValue("icon"));
        var heading = fieldset.GetValue("heading");
    
        <section class="col-md-4">
            <img src="@media.Url" alt="@media.Name" />
            <h3>@heading</h3>
            <p>@fieldset.GetValue("shortDesc")</p>
        </section>
    }
    </div>

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft