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.
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.
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?
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:
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?
Hi.
ought to work. (You can tune it with 'insertTextBefore/After' and other stuff that I omitted above).
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.
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.
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?
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
Got it to work. Thanks!
is working on a reply...