Copied to clipboard

Flag this post as spam?

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


  • Fisbenet 3 posts 23 karma points
    Jun 12, 2014 @ 11:12
    Fisbenet
    0

    Problem with unique titles for news post

     Hello,

    I have a problem. I'm trying to get the title to state the title of the news post when opening it, The problem is that the code I use only finds the pagename which in this case is news and I haven't found away to link it to the actual news post.

    Mainpage/news/spesific news update

     

    <title>Company name - <umbraco:Item field="blogHeading" useIfEmpty="pageName" runat="server"></umbraco:Item></title>

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2014 @ 11:23
    Dave Woestenborghs
    0

    Does your document type contain a field called blogHeading ?

     

    Dave

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 12, 2014 @ 11:37
    Steve Morgan
    0

    REMOVED to avoid confusion :) 

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2014 @ 11:47
    Dave Woestenborghs
    0

    Hi Steve,

    Actually he isn't using XSLT, but the Umbraco Field macro.

    I suspect that field blogHeading doesn't exist on the documenttype or that it doesn't containt a value.

    Dave

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 12, 2014 @ 12:03
    Steve Morgan
    0

    I hadn't had my first coffee-  I've removed my comment to avoid confusion! 

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2014 @ 12:09
    Dave Woestenborghs
    0

    LOL...golden rule : never go on our before you had your morning coffee :-)

  • Fisbenet 3 posts 23 karma points
    Jun 12, 2014 @ 13:52
    Fisbenet
    0

    Thanks everyone. Yes, we have a blogHeading in a field on the document with a value. I think the problem is we're loading the text content thru a macro. The homepage loads a template, let's call it "templatePage", on this templatePage we have a macro calling for the data values from the docuemt "newsItem". So more specificaly we need to get the field data from the "newsItem" thru the macro somehow and display in the "templatePage" title tag?

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 12, 2014 @ 16:10
    Steve Morgan
    0

    Sorry if I'm still misunderstanding but I think the need is to output in the homepage (or any other parent page for that matter..) your list of articles.  To do this you need a macro - this will run in the context of the homepage so you need to tell Umbraco how to get to the news articles.

    I've assumed you've got a content tree like:

    Home

       |  News

          |  Article 1

            ..... 

            Article X

    E.g. a news container under your homepage with news items below it. 

    use the following. 

    Create a Partial View Macro - paste the code in below 

    * note the bits I've scored - these need changing to represent your document aliases... note how in the loop Umbraco wants a plural of your "newsItem" e.g. "newsItems" - my example below use a stupid name "ArticlesItem" which becomes "ArticlesItems"!

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
        @{
            var homepage = CurrentPage.AncestorsOrSelf(1).First();
            @* now we need to tell Umbraco to get the News container parent *@
            var newsContainer = homepage.ArticlesMain.First();
    
    
            @* OrderBy() takes the property to sort by and optionally order desc/asc *@
            @* for each article item (note plural!) under the newsContainer *@
            foreach (var page in newsContainer.ArticlesItems.Where("Visible").OrderBy("CreateDate desc"))
            { 
                <div class="article">
                    <div class="articletitle"><a href="@page.Url">@page.Name</a></div>
                    <div class="articlepreview">@Umbraco.Truncate(@page.ArticleContents,100) <a href="@page.Url">Read More..</a></div>
                </div>
                <hr/>
            }
        }
    
    Now include this macro on your homepage template and you're there. 
  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 12, 2014 @ 16:11
    Steve Morgan
    0

    Oh and change @page.Name to @page.BlogHeading or whatever it was :) 

  • Fisbenet 3 posts 23 karma points
    Jun 12, 2014 @ 16:17
    Fisbenet
    0

    Thanks for the quick response, gonna see if I can get this working. I'll post an update as soon as possible, cheers!

Please Sign in or register to post replies

Write your reply to:

Draft