We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21740
    • 17 Posts
    Hello there,

    I have a very simple question: how do I get the parent title of a document? I read the documentation but somehow I don’t get it. I tried all combinations [[+parent]], [[++parent]] etc pp but obviously I don’t understand it.

    What I want to do?

    Say I have the following document tree

    web
    --> EN
    -----> Page 1
    -----> Page 2
    --> DE
    -----> Page 1
    -----> Page 2

    I have a header and a footer chunk for each language: header_DE, header_EN and footer_DE, footer_EN.

    Now I don’t want to duplicate my template, so I want to check the parent title to dynamically insert the appropriate header and footer in the template This I want to achieve by templates which llook like this (example):

    [[$Header_<getParentTitleofDocument>]]
    [[*content]]
    [[$Footer_<getParentTitleofDocument>]]

    which should produce

    [[$Header_DE]]
    [[*content]]
    [[$Footer_DE]]

    or

    [[$Header_EN]]
    [[*content]]
    [[$Footer_EN]]

    respectively.

    I hope this works - but for that to try I have to get the parent title smiley

    Help?

    Thanks,
    noned
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      You can get the parent ID with [[*parent]]

      Information on the tag syntax for Revolution is here: http://rtfm.modx.com/display/revolution20/Tag+Syntax

      I think you may want to use the UltimateParent though - that will travel up the navigation tree to find the highest resource.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 21740
        • 17 Posts
        Thanks, with your help I found that I was too stupid to put the variable into the template!

        I also found the exact solution what I need in this thread: After installing the getResourceField you can use
        [[getResourceField ? &id=`[[*parent]]` &field=`pagetitle`]]
        to get the title of the parent - with this I have a great switch to change the header and footer of my site, depending on the language!

        Great, thanks again smiley

        noned
          • 33968
          • 863 Posts
          Hi noned - glad you’re finding your way around but you should definitely look at Mark H’s suggestion to use UltimateParent. If you end up adding another level of resources (say, under ’Page 1’) you will run into problems as the wrong parent id will be returned.

          Try
          [[UltimateParent? &topLevel=`2`]]

          which will travel up the document tree and return the id for either the ’EN’ or ’DE’ container.