-
- 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.
-
- 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).
-
- 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?
-
- 24,544 Posts
You didn't mention that you were using the current resource.
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.