?
avatar sanderpotjer
sanderpotjer
2 Mar 2017

Steps to reproduce the issue

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.

Expected result

If you load <?php echo JHtml::_('content.prepare', ' {field X}'); ?> it should render the field with ID X.

Actual result

Output is {field X}, so not the rendered custom field.

Additional comments

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

avatar sanderpotjer sanderpotjer - open - 2 Mar 2017
avatar joomla-cms-bot joomla-cms-bot - change - 2 Mar 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 2 Mar 2017
avatar Bakual Bakual - close - 3 Mar 2017
avatar Bakual
Bakual - comment - 3 Mar 2017

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.

avatar Bakual Bakual - change - 3 Mar 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-03-03 08:46:04
Closed_By Bakual
avatar Bakual
Bakual - comment - 3 Mar 2017

by the way, in your template override, look at the item properties. $item->fields already contains all the needed data.

avatar sanderpotjer
sanderpotjer - comment - 3 Mar 2017

@Bakual I know the data is send for the article. But if this is the "expected behaviour" it is different then for {loadmodule X} for example, which seems incorrect to me.

avatar Bakual
Bakual - comment - 3 Mar 2017

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.

Add a Comment

Login with GitHub to post a comment