Copied to clipboard

Flag this post as spam?

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


  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Jun 14, 2012 @ 11:41
    Scott Hugh Alexandar Petersen
    0

    Create an xslt extension method to set page title?

    Hi all,

    I have built a usercontrol to set the title of the page from an xslt file but the file fails to render.

    I have the following which builds fine but does not work:

    uuc.dll

    using umbraco.cms.presentation;
    
    namespace uuc
    {
        public class iPage : umbraco.presentation.masterpages._default
        {
            public static void SetPageTitle(string text)
            {
                _umbraco.Current.Page.Title = text;
            }
        }
    }

    SetPageTitle.xslt

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tags.library="urn:tags.library" xmlns:url.library="urn:url.library" xmlns:iPage="urn:iPage"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tags.library url.library iPage ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:value-of select="iPage:SetPageTitle('SOMETHING')" />
    </xsl:template>
    </xsl:stylesheet>

    Now for those who wants to know why I thought of this way, then it is because I have a repo of pages which are publicly restricted and I need to show part of this information on another page, so only part of the information is actually 100% restricted. Then I want to access the page showing the page elements which are ok and then set the page title for the site as per the standards.

    So having a title property on the page and want to use that title property to set the page title from an xslt extension or similar from the xslt file - or if you have any other great idea I am all ears.

    Thanks!

    Scott

  • pat 124 posts 346 karma points
    Jun 18, 2012 @ 16:01
    pat
    0

    if you have page title as  propety in document type. you can use this value in template .

    open template simply add <title><umbraco:Item field="pageTitle" runat="server"></umbraco:Item> between <head></head> tags.

    here the pageTitle is the name of -  generic property in document type .

    so you can edit page title  any time . if you need to keep page heading different to page title keep two properties. or use one property for both

     

     

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Jun 18, 2012 @ 16:05
    Scott Hugh Alexandar Petersen
    0

    Hi pat,

    Yes I have that as well but as I get the page dynamically (at runtime) then the pageTitle is not changed. My structure is like this:

    • Frontpage
      • Subpage (this pages gets info from "Repo" which is in another structure
    • Repo
      • Page 1
      • Page 2
      • Page 3
      • Page 4
    So actually my question is how do I take the pageTitle tag from let's say Page 2 in my repo and set it at runtime from my Subpage?
    Thanks
  • Asif Malik 203 posts 339 karma points
    Jun 19, 2012 @ 15:00
    Asif Malik
    0

    Maybe i am missing something about your specific senarion, but wouldnt it be easier to just wire up your XSLT to a macro and put that in your masterpage?

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Jun 19, 2012 @ 17:01
    Scott Hugh Alexandar Petersen
    0

    Well I would still not be able to get the title tag from the other page

    As I said I have the following structure

    - Content
      - Frontpage
        - Subpage (I want to display the product pages title and not the subpages title when on this page with a querystring param - so I have put in a macro that gets the contents of the pages under the product node, now to show the contents of the product page I access the current page with a querystring param so /subpage.aspx?pid=2343)
      - Product
        - Product 1 (2342)
        - Product 2 (2343)

    It should be possible but I am a bit stuck.

  • Asif Malik 203 posts 339 karma points
    Jun 19, 2012 @ 17:10
    Asif Malik
    0

    ok I would create a property on the Subpage of type content picker, which will allow you to pick the Product 1 page.

    then in your XSLT you should be able to get the node id, and do a getXmlByNodeId .... then you have all the contents of the Product 1 page, while you are on the SubPage

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Jun 20, 2012 @ 11:01
    Scott Hugh Alexandar Petersen
    0

    lets say that I have my subpage and want to get any of the products in my Product folder by querystring then how would I set the page title?

    cause the way umbraco fields work right now is that it takes the current page title (which will always be subpage.aspx - no matter which template I use or querystring parameters are set).

    which is why if I in my xslt file could create an extension method to set the page title at runtime then I would be happy :)

    @asif - Thanks for inputting

  • Asif Malik 203 posts 339 karma points
    Jun 20, 2012 @ 11:10
    Asif Malik
    0

    well if you want to get them from the querystring, there are XSLT extension methods

    umbraco.library:Request('String key')

    umbraco.library:RequestQueryString('String key')

    umbraco.library:RequestForm('String key')

    You should be able to build in the logic you need in the XSLT file .... if you cant do everything then you can always build your own XSLT extension to return the correct text, but i would recommend you wire the XSLT (via a macro) directly into the master page

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Jun 20, 2012 @ 11:19
    Scott Hugh Alexandar Petersen
    0

    I get the thing with the request methods, which are quite straight forward.

    but what I do not get is how to set the page title.

    I don't want to test per url to set page title I want it to be a function where I can just parse text to it like

    <xsl:value-of select="iPage.SetPageTitle('my new page title')" />

    And finish

  • Asif Malik 203 posts 339 karma points
    Jun 20, 2012 @ 11:39
    Asif Malik
    0

    Not really sure how to go about doing it the way you are trying to ... another idea i had was to maybe wire the macro to a .net user control. the user control should be able to find the parent master page and change the title tag ... just a thought ... running out of ideas :)

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 19, 2012 @ 09:42
    Fuji Kusaka
    0

    @Scott have you been able to get it working? I have a queryString as well that am parsing to a page but someone cant get the page to display the value.

Please Sign in or register to post replies

Write your reply to:

Draft