<title>My site - <umbraco:Item ID="Item1" Field="title" runat="server" /></title>
I want to show "My site - current page title" title, but I get "current page title" in a browser title bar. It looks like umbraco is replacing whole content of title tag.
Did anyone notice it before? Could you advice on this issue?
I encountered pretty much the same thing recently, thought I did something somewhere wrong as it definitely worked e.g. in 4.5.2. I didn't bother very much with it as the site was still in (early) development and then we had to move the whole title tag to Xslt anyway which worked fine then. Would love to know though as well what is happening here?
You can probably rewrite it with inline xslt for a quick workaround:
<umbraco:Item ID="Item1" runat="server" field="title" xslt="concat('My site - ',{0})" xsltDisableEscaping="true"/>,
Thanks Sascha, you method worked. Unfortunately it turned out I have bigger problem. Not all nodes have title, in which case I have to fallback to generic node.Name
I'm sure xslt can solve this issue either, but amount of markup can become frustrating. (taking into consideration possible future requirement to show bookmarks in the page title)
Anyway, final solution follows:
<title id="title" runat="server">My site - <%# Title %> </title>
public partial class Master : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { title.DataBind(); }
public string Title { get { var node = Node.GetCurrent();
One alternative you might want to look at (and may it just be for the sake of it as your solution works absolutely fine) is to use the useIfEmpty attribute of <umbraco:Item> like this:
<umbraco:Item ID="Item1" runat="server" field="title" useIfEmpty="pageName" xslt="concat('My site - ',{0})" xsltDisableEscaping="true"/>
I haven't tried it out myself yet to use inline xslt with an alternative field, but maybe worth a shot.
umbraco Field replaces whole title content?
That's master page title:
<title>My site - <umbraco:Item ID="Item1" Field="title" runat="server" /></title>
I want to show "My site - current page title" title, but I get "current page title" in a browser title bar. It looks like umbraco is replacing whole content of title tag.
Did anyone notice it before? Could you advice on this issue?
Thanks!
I encountered pretty much the same thing recently, thought I did something somewhere wrong as it definitely worked e.g. in 4.5.2. I didn't bother very much with it as the site was still in (early) development and then we had to move the whole title tag to Xslt anyway which worked fine then. Would love to know though as well what is happening here?
You can probably rewrite it with inline xslt for a quick workaround:
<umbraco:Item ID="Item1" runat="server" field="title" xslt="concat('My site - ',{0})" xsltDisableEscaping="true"/>,
however that can't be it.
Thanks Sascha, you method worked. Unfortunately it turned out I have bigger problem. Not all nodes have title, in which case I have to fallback to generic node.Name
I'm sure xslt can solve this issue either, but amount of markup can become frustrating. (taking into consideration possible future requirement to show bookmarks in the page title)
Anyway, final solution follows:
<title id="title" runat="server">My site -
<%# Title %>
</title>
public partial class Master : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
title.DataBind();
}
public string Title
{
get
{
var node = Node.GetCurrent();
var title = node.GetProperty("title");
if (title != null)
{
return title.Value;
}
else
{
return node.Name;
}
}
}
}
One alternative you might want to look at (and may it just be for the sake of it as your solution works absolutely fine) is to use the useIfEmpty attribute of <umbraco:Item> like this:
<umbraco:Item ID="Item1" runat="server" field="title" useIfEmpty="pageName" xslt="concat('My site - ',{0})" xsltDisableEscaping="true"/>
I haven't tried it out myself yet to use inline xslt with an alternative field, but maybe worth a shot.
Cheers,
Sascha
Thanks Sascha, I'll keep this trick up my sleeve :)
is working on a reply...