1

When you click on a tag inside an article you go to com-tags view-tag, that is created by com_tags/views/tag/tmpl/default_items. This is a blog with articles with the same tag. I want there, inside every article to display also the tags. I have created an override for this view: ../html/com_tags/tag/tag_items.php and added there this code (took it from /components/com_content/views/article/tmpl/default.php)

<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>

According to Joomla "Sharing layouts across views or extensions with JLayout" documentation I should have my tags there, but obviously I have somewhere an issue as I am receiving an error on the front end.

Call to a member function render() on null

The code is (I can not manage to show it well, but it is the original Joomla /components/com_tags/views/tag/tmpl/default_items.php):

authorise('core.edit', 'com_tags');
$canCreate    = $user->authorise('core.create', 'com_tags');
$canEditState = $user->authorise('core.edit.state', 'com_tags');

JFactory::getDocument()->addScriptDeclaration("
        var resetFilter = function() {
        document.getElementById('filter-search').value = '';
    }
");

?>
toString()); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
    params->get('show_headings') || $this->params->get('filter_field') || $this->params->get('show_pagination_limit')) : ?>
        
            params->get('filter_field')) : ?>
                
                    
                        
                    
                    escape($this->state->get('list.filter')); ?>" class="inputbox" onchange="document.adminForm.submit();" title="" placeholder="" />
                    " onclick="document.adminForm.submit();" class="btn">
                        
                    
                    " class="btn" onclick="resetFilter(); document.adminForm.submit();">
                        
                    
                
            
            params->get('show_pagination_limit')) : ?>
                
                    
                        
                    
                    pagination->getLimitBox(); ?>
                
            
            
            
            
            
            
        
    
    items)) : ?>
        

items as $i => $item) : ?> core_state == 0) : ?> "> clearfix"> type_alias === 'com_users.category') || ($item->type_alias === 'com_banners.category')) : ?>

escape($item->core_title); ?>

link); ?>"> escape($item->core_title); ?>

event->afterDisplayTitle; ?> core_images); ?> params->get('tag_list_show_item_image', 1) == 1 && !empty($images->image_intro)) : ?> link); ?>"> image_intro); ?>" alt="image_intro_alt); ?>"> params->get('tag_list_show_item_description', 1)) : ?> event->beforeDisplayContent; ?> core_body, $this->params->get('tag_list_item_maximum_characters')); ?> event->afterDisplayContent; ?>
9
  • Something has gone with the display of the code - you've somehow missed out the left hand side of it. Also I need to see the code of your override, not the original joomla code! Could you try again copying it into your question. Sep 14, 2020 at 10:44
  • Yes I know, I just add the code inside <pre><code>.... Anyway, I use this file in my override: /components/com_tags/views/tag/tmpl/default_items.php and I just add these two lines of code inside:<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> <?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
    – geoplous
    Sep 14, 2020 at 13:41
  • Yes, but that won't work. You need to add the code I mentioned in the answer. And you need to add it in the right place, because the Joomla code iterates over the items which have the tag being output, so you need to put it appropriately inside the loop. Sep 14, 2020 at 13:51
  • Yes I added this code per your instructions: <?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> <?php echo $item->tagLayout->render($item->tags->itemTags); ?> No error but no output. Code is in correct position under the line 103 after introtext, inside the loop
    – geoplous
    Sep 14, 2020 at 14:15
  • Sorry, forgot to remove the $this on the parameter inside the getItemTags call, so I've changed the answer I posted. I've coded it up as an override and got it to work ok. Sep 14, 2020 at 18:16

1 Answer 1

1

The problem is that you haven't captured the tags associated with the article. The tags aren't held in the same table as the article data, so they need special code in order to be included. If you look in the /components/com_content/views/article/view.html.php file you'll see

$item->tags = new JHelperTags;
$item->tags->getItemTags('com_content.article', $item->id);

This sets up the itemTags property in the JHelperTags object, and so can be referenced by $item->tags->itemTags. This is what you'll have to do in your layout file.

Also in the tags default_items.php file $this doesn't refer to the same thing as the $this in the com_content default.php file. In the tags layout file each item is referenced using $item so you'll have to use it instead of $this->item.

So for example in the default_items.php override you can put just under the line:

<?php foreach ($this->items as $i => $item) : ?>

the following code to output the other tags of articles:

<?php 
    if ($item->type_alias === 'com_content.article')
    {
        $item->tags = new JHelperTags;
        $item->tags->getItemTags('com_content.article', $item->id);
        $item->tagLayout = new JLayoutFile('joomla.content.tags'); 
        echo $item->tagLayout->render($item->tags->itemTags); 
    }
?> 
2
  • Hi, I changed it to : <?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> <?php echo $item->tagLayout->render($item->tags->itemTags); ?> No error now, but also no output. I use standard Joomla code, no tweaks at all.
    – geoplous
    Sep 14, 2020 at 5:45
  • Can you update your original question with your code from the layout file that outputs each article. Sep 14, 2020 at 8:56

Your Answer

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

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