We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24374
    • 322 Posts
    So, I'm not really sure why there are different methods of grabbing content fields. There's:

    $modx->resource->content
    $modx->resource->get('content')
    $modx->resource->getContent()

    What's the difference? I seem to remember some method(s) may grab rendered content rather than raw (including tags), but I'm not sure. I tend to use all three of these, with no real reason to pick one over the other.
      • 22427
      • 793 Posts
      Consider also getValue() - see Bob's Blog.
        • 3749
        • 24,544 Posts
        Among those three methods, getContent() is the "official" method. It will still work if the name of the content field changes and it will work to get the content of other objects (chunks, templates, snippets, and plugins) where the name of the content field is not 'content'.

        Using getValue() is significantly faster and uses much less memory, but it depends on the field being named 'content' (a fairly safe assumption for the near future and possibly beyond).

        All those methods will get the raw content of the field (i.e., no tags will be processed).
          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
          • 24374
          • 322 Posts
          I thought getValue() is only used with queries. Is that right? Why would I want to use this to get the content of the current resource, for which no query is needed?
            • 3749
            • 24,544 Posts
            You didn't mention that you were using the current resource. wink

            In that case, I generally use this:

            $modx->resource->get('content');


            getContent() is definitely slower, and the above follows the OOP principle of getting member variables through getters rather than directly. Theoretically, the content member you get with $modx->resource->content could be made private at some point in the future.
              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