I created a custom field plugin. I need to get an article id in blog category view in plugin layout file: /plugins/fields/my_plugin/tmpl/default.php.

In my article view, I can get it from $app->getInput()->get('id'), but what's the way in blog category view?

In this file, I have a 2 objects: $field - there is a field object and $fieldParams.

However, inside the plugin layout file, I do not have an article object.

1 Answer 1


Field value is rendered during onCustomFieldsPrepareField event which takes 3 arguments: the context string, content item object and the field object. The content item is the second argument passed to the event. If your plugin extends Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin class, it should have this function signature:

public function onCustomFieldsPrepareField($context, $item, $field)

In that case the content item is $item. You can access it inside the field layout. Just be aware that custom field plugins are normally designed to work with multiple content types which may not have the same properties as articles. If the logic in your plugin is specific to content articles, you should perform a context check to ensure the logic only runs when articles are concerned:

if ($context === 'com_content.article')
    // Your code here
    $articleId = $item->id;
  • Thanks for the answer, this is what I need. I really intended to work with different types of content, not only with articles, and I will check the context for the presence of the "category" string. Commented Aug 29, 2022 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.