If you add {field X} in an article it the custom field with id X is rendered.
If you add something like <?php echo JHtml::_('content.prepare', ' {field X}'); ?>
in e.g. your template override the field is not being rendered.
If you load <?php echo JHtml::_('content.prepare', ' {field X}'); ?>
it should render the field with ID X.
Output is {field X}
, so not the rendered custom field.
Right now the only place where {field X} is rendered is if you add this tag in the article text itself. With a quick look at the code I expect this has to do with the context, if you prepare the content via <?php echo JHtml::_('content.prepare', ' {field X}'); ?>
the context is text, so this is causing the return: https://github.com/joomla/joomla-cms/blob/staging/plugins/content/fields/fields.php#L65
Labels |
Added:
?
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-03-03 08:46:04 |
Closed_By | ⇒ | Bakual |
by the way, in your template override, look at the item properties. $item->fields
already contains all the needed data.
Yes, it is different from {loadmodule} one in this case because here we need the full item and the context, not only the plugin tag.
You would at least have to do something like <?php echo JHtml::_('content.prepare', ' {field X}', '', 'com_content.article'); ?>
to pass the proper context. But I think it would still miss the field (value) itself since the fields are stored in the $item and you're only passing the text here.
But you could use one of the three automatic positions to display that field. Sounds more useful to me than to hardcode the id of a field into an override.
JHtml::_('content.prepare', ' {field X}');
only passes a text, not the whole object. You need to trigger the event direct using the event dispatcher. The JHtml method doesn't work.And yes, the context is important as well.
So this is not a bug, it is expected behavior.