Copied to clipboard

Flag this post as spam?

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


  • malar 97 posts 206 karma points
    May 02, 2018 @ 08:56
    malar
    0

    Tag

    Hi,

    I have written this code about tag. It is displaying error about missing a closing "}" character . it is not original error. In the code i have selected two places , I think , that code is the problem. Can you please see my code.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Globalization;

    @{

    var newsNodes = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "nyhed");
    var tagCategories = Umbraco.TypedContent(1150).Children.Where(x => x.DocumentTypeAlias == "indholdmappe" || x.DocumentTypeAlias == "InformationMappe");
    

    } @foreach (var news in newsNodes) { string caption = ""; caption = news.GetPropertyValue

       string catName = news.Ancestors("Category").First().Name; 
        var newsTag = catName.Substring(catName.Length - 2) == "er" ? catName.Substring(0,catName.Length - 2) : catName;
        @* newsTag kan bruges til at skrive hvilken kategori nyheden er
           Bliver ikke brugt men kan skrive f.eks. (Reportage/Nyhed eller lign.)
        *@  
        string tags1 = @news.tags;
        List<string> tagsPage = tags1.Split(',').ToList<string>();
        <div class="box">
            <a href="@news.Url">
                <div class="newsContainer row">             
    
                    <div class="newsText col-md-7 col-lg-8">
                        <p id="publishDate2">@caption</p>
                        <h1>@news.GetPropertyValue("title")</h1>
                        <div class="newsTags" style="text-align:center;">
                            <ul class="tagListNews">
                            @foreach (var tag in tagsPage) {
                                    foreach (var catTag in tagCategories) {                                         
                                        if (tag == catTag.tagName) {
                                            string tagColor = "#"[email protected];                                             
                                            if (tagColor == "#FFFFFF") {
                                                tagColor = "#000000";
                                            }
                                            <a href="@catTag.Url">
                                                <li style="background-color: @tagColor">@tag</li>
                                            </a>
                                        }           
                                    }
                                }
                            </ul>
                            <div style="clear: both"></div>
                        </div>
    
                    </div>
                </div>
            </a>
    
        </div>
    }
    <a class="addMore" href="#" title="">
        <div class="botAdd">
            Indlæs flere nyheder
        </div>
    </a>
    

    enter image description here

    Error: enter image description here

  • malar 97 posts 206 karma points
    May 02, 2018 @ 09:28
    malar
    0

    Can you please help me.

  • malar 97 posts 206 karma points
    May 03, 2018 @ 11:59
    malar
    0

    Hi

    What happened? Can anyone please help me. it is challenging to learn this tag code

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    May 03, 2018 @ 14:14
    Michaël Vanbrabandt
    0

    Hi malar,

    its really hard to identify the problem here because your code is not nicely structured in your post.

    One thing I see is you can remove the @ from in front of the news.tags;

    string tags1 = @news.tags;
    

    Also here:

    string tagColor = "#"[email protected];
    

    you can remove the @.

    Can you try that and see what result you have?

    Thanks!

    /Michaël

  • malar 97 posts 206 karma points
    May 08, 2018 @ 07:32
    malar
    0

    Hi Michaël ,

    Yes , i removed the @ , it is displaying error. Can you please see my code.

    enter image description here

    Error:

    Umbraco.Core.Models.IPublishedContent 'does not contain a definition for' tags' and an extension method 'tags' was not found that accepts a first argument of the type' Umbraco.Core.Models.IPublishedContent '(do you need a' using ' 'directive or a assembly reference?)

    enter image description here

  • malar 97 posts 206 karma points
    May 08, 2018 @ 07:33
    malar
    0

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

    var newsNodes = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "nyhed");
    var tagCategories = Umbraco.TypedContent(1150).Children.Where(x => x.DocumentTypeAlias == "indholdmappe" || x.DocumentTypeAlias == "InformationMappe");
    

    }

    @foreach (var news in newsNodes) {
        string catName = news.Ancestors("Category").First().Name; 
         var newsTag = catName.Substring(catName.Length - 2) == "er" ? catName.Substring(0,catName.Length - 2) : catName;
        string tags1 = news.tags;
        List<string> tagsPage = tags1.Split(',').ToList<string>();
    
        <div class="box">
            <a href="@news.Url">
                <div class="newsContainer row">             
    
                    <div class="newsText col-md-7 col-lg-8">
                        <h1>@news.GetPropertyValue("title")</h1>
                        <div class="newsTags" style="text-align:center;">
                            <ul class="tagListNews">
                            @foreach (var tag in tagsPage) {
                                    foreach (var catTag in tagCategories) {                                         
                                        if (tag == catTag.tagName) {
                                            string tagColor = "#"+catTag.tagColor;                                              
                                            if (tagColor == "#FFFFFF") {
                                                tagColor = "#000000";
                                            }
                                            <a href="@catTag.Url">
                                                <li style="background-color: @tagColor">@tag</li>
                                            </a>
                                        }           
                                    }
                                }
                            </ul>
                            <div style="clear: both"></div>
                        </div>
    
                    </div>
                </div>
            </a>
    
        </div>
    }
    <a class="addMore" href="#" title="">
        <div class="botAdd">
            Indlæs flere nyheder
        </div>
    </a>
    
Please Sign in or register to post replies

Write your reply to:

Draft