Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1520 karma points
    Jul 26, 2018 @ 15:10
    Paul de Quant
    0

    Problem outputting tags

    Hello,

    I have a property type of Umbraco.Tags, which I've added to a document type. On my page I have typed a number of tags, that I would ideally like to output on the front-end.

    I cannot work out how to do this.

    I thought this was enough:-

    string[] tagList = Model.Content.GetPropertyValue<string>("faqsTaxonomy").Split(',');
    

    Then something like this:-

                <ul>
                @foreach (var tag in tagList)
                {
                    <li>
                        <a class="badge @(Request.QueryString["tag"] == tag ? "badge__active" : string.Empty)" href="?tag=@tag">
                            @tag
                        </a>
                    </li>
                }
            </ul>
    

    But I get is this "System.String[]" outputted to screen, Can anyone tell me where I'm going wrong.

    I'm using Umbraco 7.11.1

    Thanks

    Paul

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 26, 2018 @ 15:20
    Jan Skovgaard
    0

    Hi Paul

    Since version 7.6 Umbraco ships with a value converter for datatypes by default. Therefore you should be able to render the tags like in this example no matter if you're using CSV or JSON as the storage option.

    @if(Model.Content.FaqsTaxonomy.Any()){
        <ul>
           @ foreach(var tag in Model.Content.FaqsTaxonomy){
                <li>
                    <a class="badge @(Request.QueryString["tag"] == tag ? "badge__active" : string.Empty)" href="?tag=@tag">
                        @tag
                    </a>
                </li>
            }
        </ul>
    }
    

    Does this work out for you?

    /Jan

  • Paul de Quant 403 posts 1520 karma points
    Jul 26, 2018 @ 15:25
    Paul de Quant
    0

    Hi Jan,

    Thanks for the reply, I managed to work it out another way.

    string[] tagList = Model.Content.GetPropertyValue<string[]>("FaqsTaxonomy");
    

    I was using the string type when I should have been using the string[] type. Also I didn't need the split.

    Thanks

    Paul

  • William Charlton 171 posts 218 karma points
    Aug 25, 2020 @ 11:33
    William Charlton
    0

    I have a similar problem. I have added a property "keywords" to a Document Type and I thought I'd try the Tags editor. You'd think this was a common usage for Tags and plenty of working examples - not so - it seems. It works well until I try to output the tag list in my keywords meta tag.

    I can't seem to output the values for a page though. The code I have (copied from this thread) is:

    @{
        string[] tagList = Model.Content.GetPropertyValue<string[]>("keywords");
    }
    <meta name="Keywords" content="@tagList" />
    

    The output I get is:

    <meta name="Keywords" content="System.String[]" />
    

    Any ideas what I'm doing wrong?

    I should add I'm using Umbraco version 7.7.6

    Update: I've changed the editor type to a textbox and it works fine - although I don't have the nice functionality of the Bootstrap style typeahead etc. Small sacrifice but it looks like Umbraco is missing something - or I am.

Please Sign in or register to post replies

Write your reply to:

Draft