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 39 posts 274 karma points
    Nov 30, 2018 @ 12:12
    Jesper Skjønnemand
    0

    tags don't render

    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 4457 posts 17970 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 39 posts 274 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.

  • louisjrdev 107 posts 343 karma points c-trib
    Nov 30, 2018 @ 14:37
    louisjrdev
    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 91 posts 456 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 39 posts 274 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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies