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

    I am trying to output the page title of a document’s parent onto a page but I’m not having much luck.

    I have used [*parent*] in the main template, which outputs the id of the documents parent, I can’t find any parameters which would allow me to output the pagetitle.

    I have seen the code $parent = $modx->getParent(55,1,’pagetitle’); in the documentation but I don’t know where to put in this code. Does it or can it go into a chunk, snippet or template variable?
    Would I have to change the code to: $parent = $modx->getParent([*id*],1,’pagetitle’);

    Thanks,
    Mark
      • 22303 MODX Staff
      • 10,725 Posts
      Search for the getField snippet. You can get a property for another document with this, and simply pass it the fieldname and document id, i.e. [*parent*], you want to get the value from.
        • 18839
        • 39 Posts
        Thanks OpenGeek,

        With regard to the code $parent = $modx->getParent(55,1,’pagetitle’); can it go inside a TV or a chunk or snippet?
        What is the best practice?
        I will need this kind of functionality in the future, and I couldn’t find info on this in the docs...
          • 6726
          • 7,075 Posts
          Can’t answer that, but as Jason said, try with GetField

          [tt][!GetField? &docid=`[*parent*]` &field=`pagetitle`!][/tt]

          :)
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: mb07 at Sep 25, 2007, 02:20 PM

            With regard to the code $parent = $modx->getParent(55,1,’pagetitle’); can it go inside a TV or a chunk or snippet?
            What is the best practice?
            I will need this kind of functionality in the future, and I couldn’t find info on this in the docs...
            Snippets, plugins, and modules represent PHP code, so it would have to go in one of those; a snippet in this case. There is plenty of information describing the differences between these types of MODx components in the documentation.