Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Dec 11, 2017 @ 16:34
    blackhawk
    0

    how to properly render tags

    I'm on Umbraco 7.7.2 with Models Builder enabled. I created keywords for a page based on Umbraco Tags. I would like to render these tag values out to page. On one of my child templates, I have the following logic...

         @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.FFacol1>
         @using ContentModels = Umbraco.Web.PublishedContentModels;
         @{
                Layout = "Master.cshtml";
          }
    
        @section Keywords {
    
        @{
            var mkeywords = Model.Keywords;
               foreach (var item in @mkeywords) { 
               @item
               }
           }
       }
    

    ...But when I look at my page, it shows all my values compacted together like this....

    <meta name="keywords" content="value1value2value3value4etc..."
    

    How can I get proper spacing and commas in between each value?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Dec 11, 2017 @ 16:58
    Kevin Jump
    100

    Hi

    you can replace the loop with a string.Join command

    @string.Join(", ", Model.keywords) 
    

    this should output something like,

    "Value1, Value2, Value3, ....."
    
  • blackhawk 313 posts 1368 karma points
    Dec 11, 2017 @ 17:11
    blackhawk
    0

    Wow that is super short compared to a foreach loop! It works for me. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft