Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 11 posts 131 karma points
    Nov 30, 2018 @ 12:12
    Jesper Skjønnemand
    0

    Not having much success with rendering tags in my template.

    The (very simple) template looks something like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = "MasterTemplate.cshtml";
    }
    
    @{
        var topics = Model.Content.GetPropertyValue<string>("pageTopics");
        <p>This is a page about @topics</p>
    } 
    

    I hope to render something like

    This page is about TESTING, UMBRACO, CLOUD, TAGS

    But all I get is

    This page is about System.String[]

    What am I missing?

  • Dennis Aaen 4404 posts 17786 karma points admin hq c-trib
    Nov 30, 2018 @ 12:21
    Dennis Aaen
    0

    Hi Jesper,

    Can you please give this a go.

    @if(Model.Content.pageTopics.Any()){
        <ul>
            @foreach(var tag in Model.Content.pageTopics){
                <li>@tag</li>
            }
        </ul>
    }
    

    Also make sure that your property is called pageTopics and the property is on the page that you are render in the browser.

    Hope this helps,

    /Dennis

  • Jesper Skjønnemand 11 posts 131 karma points
    Nov 30, 2018 @ 12:30
    Jesper Skjønnemand
    0

    Hi Dennis

    When I insert this code, preview (Umbraco Canvas Designer) displays Server Error in '/' Application. Runtime Error and some more text in yellow boxes.

    I have triple (actually more) checked. The property name is pageTopics, and my test page contains tags.

    Tags are stored as JSON, not CSV.

    I am running Umbraco Cloud.

  • Louis Jackson-Rees 47 posts 175 karma points
    Nov 30, 2018 @ 14:37
    Louis Jackson-Rees
    2

    Can you try:

    @if(Model.Content.GetPropertyValue<IEnumerable<string>>("pageTopics") !=null){
    <ul>
        @foreach(var tag in Model.Content.GetPropertyValue<IEnumerable<string>>("pageTopics")){
            <li>@tag</li>
        }
    </ul>
    

    }

  • Rasmus Eeg 78 posts 419 karma points c-trib
    Dec 01, 2018 @ 15:38
    Rasmus Eeg
    100

    Hi Jesper,

    Here is how you should do it:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = "MasterTemplate.cshtml";
        var topics = Model.Content.GetPropertyValue<string[]>("pageTopics");
    }
    
     <p>This is a page about @string.Join(", ", topics)</p>
    

    If you insist on the tags being uppercase, i would to the following:

    var topics = Model.Content.GetPropertyValue<string[]>("pageTopics").Select(x=> x.ToUpperInvariant());
    
  • Jesper Skjønnemand 11 posts 131 karma points
    Dec 02, 2018 @ 15:49
    Jesper Skjønnemand
    0

    Hi all

    Suggestions from Louis and Rasmus both worked. You just resqued my whole week. Thanks.

    Jesper

Please Sign in or register to post replies

Write your reply to:

Draft