- Posts: 7
COMMUNITY FORUM
[SOLVED] $item->tags empty in tag.php
- muhzilla muhzilla
-
Topic Author
- Offline
- New Member
Less
More
9 years 1 month ago - 9 years 1 month 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.
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: 9 years 1 month ago by muhzilla muhzilla.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 1 month 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 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); ?>
Please Log in or Create an account to join the conversation.
- muhzilla muhzilla
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 7
9 years 1 month 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.
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 1 month 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.
You should add the $task == 'tag' in the check above.
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.
Please Log in or Create an account to join the conversation.
- muhzilla muhzilla
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 7
9 years 1 month 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
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 7
9 years 1 month ago - 9 years 1 month 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?
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: 9 years 1 month ago by muhzilla muhzilla. Reason: updated
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 1 month 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
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
Please Log in or Create an account to join the conversation.
- muhzilla muhzilla
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 7
9 years 1 month 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 1 month ago #152799
by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] $item->tags empty in tag.php
You 're welcome :)
Please Log in or Create an account to join the conversation.