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

Answered Retrieve title

    • 11121
    • 79 Posts
    I want to retrieve the <title> of the current page and use it in a chunk. I don't want pagetitle but <title>.

    Any ideas?

    This question has been answered by BobRay. See the first response.

    [ed. note: gordonas last edited this post 8 years, 1 month ago.]
    • discuss.answer
      • 3749
      • 24,544 Posts
      A MODX resource (e.g., the current page) has no title field unless you've created a Template Variable called 'title' (without the quotes). In that case it would be:

      [[*title]]


      You might mean the longtitle field, which would be:

      [[*longtitle]]



      The available fields for a resource are listed here: http://bobsguides.com/modx-object-quick-reference.html#modResource
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 11121
        • 79 Posts
        Quote from: BobRay at Feb 02, 2016, 08:07 PM
        A MODX resource (e.g., the current page) has no title field unless you've created a Template Variable called 'title' (without the quotes). In that case it would be:

        [[*title]]


        You might mean the longtitle field, which would be:

        [[*longtitle]]



        The available fields for a resource are listed here: http://bobsguides.com/modx-object-quick-reference.html#modResource


        Thank you Bob. I will try to find another way to solve my problem.
          • 13226
          • 953 Posts
          Although you have marked the post as answered I think you should take a closer look at the default resource content fields

          You say you want the <title> tag - that tag is NOT pre-defined unless you do it yourself, an example or two:

          <title>[[*pagetitle]]</title>
          <title>[[*longtitle]]</title>
          <title>[[*menutitle]]</title>
          <title>[[*introtext]]</title>


          You can obviously create your own template variable and use that in the title tag

          <title>[[*mytemplatevariable]]</title>


          So a very basic template could look like the following:

          <!DOCTYPE HTML>
          <html>
          <head>
          <meta charset="[[++modx_charset]]">
          <title>[[*mytemplatevariable]]</title>
          </head>
          <body>
          [[*content]]
          </body>
          </html>


          So, if you want to use an element from the page in your chunk you simply add that element, an example:

          Chunk name: myChunk
          Chunk content: [[*mytemplatevariable]]

          I hope this helps to understand a little more
            • 3749
            • 24,544 Posts
            I'm sorry I misread your question and glad iusemodx pointed it out.

            There's no way (short of using JavaScript) to "capture" what's in the title tag. What you can do, though, is to look at the HTML code for the <title> tag in your template. (You can't do a view source, because at that point whatever tag was there will have been replaced.)

            Once you find a tag like the ones iusemodx listed, you can use that exact same tag in a chunk to get the same thing that's in the title tag.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting