Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1159 karma points
    Oct 27, 2011 @ 00:42
    Connie DeCinko
    0

    Cannot get page title when set by Umbraco

    I have a usercontrol that needs the page title. In my test code, outside of Umbraco, Page.Title correctly gives me this information. When the usercontrol is on an Umbraco page, I get nothing. My title is set via the code below:

    <title><umbraco:Item field="pageTitle" textIfEmpty="Protecting the Public While Advancing the Legal Profession" insertTextBefore="State Bar of Arizona :: " htmlEncode="true" stripParagraph="true" runat="server"></umbraco:Item></title>

    If I Insert any text inside the title tag but before the umbraco:item tag, that is visible to my usercontrol. It appears Umbraco is injecting the title after the page is created.

    How do I get that value in my usercontrol?

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 27, 2011 @ 19:59
    Rodion Novoselov
    0

    Hi.

     <umbraco:Item field="pageName" runat="server" />

    ought to work. (You can tune it with 'insertTextBefore/After' and other stuff that I omitted above).

  • Connie DeCinko 931 posts 1159 karma points
    Oct 27, 2011 @ 20:25
    Connie DeCinko
    0

    Right, that's how I get the value in my XSLT. But how can I get the same value in my .NET usercontrol?  That's where I need the value.

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 27, 2011 @ 21:14
    Rodion Novoselov
    0

    In the most generic case you can get the current page id anywhere through a sort of 'hack' - just get HttpContext.Current.Items["pageID"] - it keeps the id of a current page. Then you can use library methods to access other document properties through its ID. And also in case you have your control wrapped with a macro you can pass any page property in more 'official' way through advanced macro parameter syntax. Like "[#pageName]" and so on.

  • Connie DeCinko 931 posts 1159 karma points
    Oct 27, 2011 @ 22:49
    Connie DeCinko
    0

    Well since I call a macro in my master template to load the usercontrol, sounds like that would be the best way to do this.  Where can I find an example?

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 27, 2011 @ 23:10
    Rodion Novoselov
    0

    For instance, there's a video tutorial about how macro parameters are passed to a wrapped asp.net user control:

    http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/macro-parameters/TVPlayer

    and below is the description of special parameter syntax ("the bracket syntax") that allows to automatically pass current page's properties, query string arguments or cookies to a macro:

    http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax

     

  • Connie DeCinko 931 posts 1159 karma points
    Oct 28, 2011 @ 00:03
    Connie DeCinko
    0

    Got it to work.  Thanks!

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies