Copied to clipboard

Flag this post as spam?

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


  • eugenekr 10 posts 30 karma points
    Mar 14, 2011 @ 00:34
    eugenekr
    0

    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!

  • Sascha Wolter 615 posts 1101 karma points
    Mar 14, 2011 @ 01:14
    Sascha Wolter
    0

    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.

  • eugenekr 10 posts 30 karma points
    Mar 14, 2011 @ 06:08
    eugenekr
    0

    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;
                    }
                }
            }
        }

  • Sascha Wolter 615 posts 1101 karma points
    Mar 14, 2011 @ 06:25
    Sascha Wolter
    0

    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

  • eugenekr 10 posts 30 karma points
    Mar 14, 2011 @ 06:41
    eugenekr
    0

    Thanks Sascha, I'll keep this trick up my sleeve :)

Please Sign in or register to post replies

Write your reply to:

Draft