Copied to clipboard

Flag this post as spam?

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


  • James Taylor 14 posts 124 karma points
    Apr 04, 2017 @ 09:41
    James Taylor
    0

    Compilation error in macro - help!

    Hi All,

    I'm creating a Razor macro to generate an RSS feed for the NewsItems on my site.

    The macro is generating a compilation error CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'photoProvider'. Commenting the appropriate line out and the macro works just fine.

    Here's what I'm doing:

    var root = Model.Content.AncestorOrSelf();
    var nodes = root.Descendants("NewsItem").Take(20);
    
    ## some RSS stuff here ###
    
    foreach (var item in nodes) {
        <item>
             ### RSS item stuff here ###
             @if(item.HasValue("photoProvider")) {
                 <media:credit scheme="urn:ebu">Photo provided by: @item.photoProvider</media:credit>
             }
        </item>
      }
    

    All the other @item.somethings work fine as expected (not shown here) and I've double-checked I've got the property name correct... I've spent too long trying to make this work... any help would be appreciated!

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 04, 2017 @ 10:01
    Alex Skrypnyk
    100

    Hi James

    You have to use "GetPropertyValue" method for accessing property values:

    <media:credit scheme="urn:ebu">Photo provided by: @item.GetPropertyValue("photoProvider")</media:credit>
    

    You can use syntax like .propertyAlias only if "item" is dynamic, and it's not the good way to do it. Look into strongly typed approach and Models builder if you want to avoid using "GetPropertyValue" method.

    https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Umbraco.ModelsBuilder

    Hope it make sense for you.

    Thanks,

    Alex

  • James Taylor 14 posts 124 karma points
    Apr 04, 2017 @ 11:09
    James Taylor
    0

    Many thanks, Alex.

    I'm a PHP guy and Umbraco is all a bit voodoo to me :)

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 04, 2017 @ 11:58
    Alex Skrypnyk
    0

    You are welcome, James!

    Write if some questions!

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft