3

I have created a content plugin which adds extra field on Joomla default article editor window and everything working as expected.

But the problem is with existing/old articles created before installing the plugin.

Here what I added on template/html/com_content/article/default.php

$checkPlugin = JPluginHelper::getPlugin('content', 'customdata');

<?php if ($checkPlugin && !empty($attributes->subtitle) : ?>
    <div><?php echo $attributes->subtitle; ?></div>
<?php endif; ?>

It's working perfectly when I add new article, but with existing articles showing below error:

Notice: Undefined property: stdClass::$subtitle in .......\html\com_content\article\default.php on line 41

What I'm doing wrong?

3

Try using isset() to check if the object property is actualy set, like so:

<?php if (!empty($attributes->subtitle) && isset($attributes->subtitle)) : ?>
    <div><?php echo $attributes->subtitle; ?></div>
<?php endif; ?>
  • Thanks, It's working. Do I still need to check whether plugin installed or not ($checkPlugin)? – Sifur Apr 25 '17 at 15:38
  • No, you don't need to. If $attributes->subtitle depends on the plugin and the plugin is disabled, then the isset($attributes->subtitle) will return false ;) – Lodder Apr 25 '17 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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