Keyword

[SOLVED] $item->tags empty in tag.php

  • muhzilla muhzilla
  • muhzilla muhzilla's Avatar Topic Author
  • Offline
  • New Member
More
8 years 6 months ago - 8 years 5 months ago #152604 by muhzilla muhzilla
[SOLVED] $item->tags empty in tag.php was created by muhzilla muhzilla
Hi there,

I am currently trying to create a new subtemplate for K2. I am using the K2 tools Tag Cloud module and would like to display the Item's tags. However, I found that when trying to output the tags, the $item->tags array is empty.

Below is the code from my tag.php. The code for outputting the tags is actually taken from category_item.php where it is working fine.
<?php echo $item->params->get('catItemTags'); ?> <!-- outputs 1, so tags should be present -->
<?php echo count($item->tags); ?> <!-- outputs 0, so array is empty -->

<span><?php echo JText::_('K2_TAGGED_UNDER'); ?></span>
<ul class="catItemTags">
   <?php foreach ($item->tags as $tag): ?>
         <li><a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a></li>
   <?php endforeach; ?>
</ul>
Last edit: 8 years 5 months ago by muhzilla muhzilla.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #152649 by Krikor Boghossian
Replied by Krikor Boghossian on topic $item->tags empty in tag.php
This is not really needed, since the check applies to a different view.
<?php echo $item->params->get('catItemTags'); ?> <!-- outputs 1, so tags should be present -->
(and the trailing endif as well)

What does this produce?
<?php var_dump($item->tags); ?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • muhzilla muhzilla
  • muhzilla muhzilla's Avatar Topic Author
  • Offline
  • New Member
More
8 years 6 months ago #152697 by muhzilla muhzilla
Replied by muhzilla muhzilla on topic $item->tags empty in tag.php
Hi Krikor,
the output for your line is NULL, so the variable seems to be not set at all.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #152709 by Krikor Boghossian
Replied by Krikor Boghossian on topic $item->tags empty in tag.php
Unfortunately the tags are not available in the object.

You can hack K2 and add them into the model, but you should backup before and keep a backup of your edits at all times.
In the /components/com_k2/models/item.php locate around line 107 the following block.
		if (($view == 'item' && ($item->params->get('itemTags') || $item->params->get('itemRelated'))) || ($view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemTags')) || ($view == 'itemlist' && $task == 'user' && $item->params->get('userItemTags')) || ($view == 'latest' && $params->get('latestItemTags')))

You should add the $task == 'tag' in the check above.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • muhzilla muhzilla
  • muhzilla muhzilla's Avatar Topic Author
  • Offline
  • New Member
More
8 years 6 months ago #152714 by muhzilla muhzilla
Replied by muhzilla muhzilla on topic $item->tags empty in tag.php
Thanks Krikor, I will try this soon. I would suggest to have all item properties present in all of the different views to be consistent. Maybe this could be done in future versions of K2? :)

Please Log in or Create an account to join the conversation.

  • muhzilla muhzilla
  • muhzilla muhzilla's Avatar Topic Author
  • Offline
  • New Member
More
8 years 6 months ago - 8 years 6 months ago #152719 by muhzilla muhzilla
Replied by muhzilla muhzilla on topic $item->tags empty in tag.php
For now, your solution works fine Krikor, thanks a lot! One more question: The archive view (executed when using the K2 tools archive functionality) seems to be controlled by the file generic.php. Is there any way to apply templates to the archive view, too? Otherwise I would have to modify the generic.php, which is another file I am actually not supposed to modify :/

Also, I would like to have the tags available in the archive view as well. What would I need to add to the check in /components/com_k2/models/item.php to accomplish this?
Last edit: 8 years 6 months ago by muhzilla muhzilla. Reason: updated

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #152737 by Krikor Boghossian
Replied by Krikor Boghossian on topic $item->tags empty in tag.php
Thanks :)
Actually these issues have been addressed in v3.
As for the generic.php, you can use the $task='date' to differentiate the date view from the other views which use the generic file.

You can modify generic.php freely provided you use overrides
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • muhzilla muhzilla
  • muhzilla muhzilla's Avatar Topic Author
  • Offline
  • New Member
More
8 years 5 months ago #152768 by muhzilla muhzilla
Replied by muhzilla muhzilla on topic [SOLVED] $item->tags empty in tag.php
Excellent, thank you Krikor! Looking forward to V3 ;)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #152799 by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] $item->tags empty in tag.php
You 're welcome :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum