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>
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?
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.
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>
Does your document type contain a field called blogHeading ?
Dave
REMOVED to avoid confusion :)
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
I hadn't had my first coffee- I've removed my comment to avoid confusion!
LOL...golden rule : never go on our before you had your morning coffee :-)
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?
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"!
Oh and change @page.Name to @page.BlogHeading or whatever it was :)
Thanks for the quick response, gonna see if I can get this working. I'll post an update as soon as possible, cheers!
is working on a reply...