Keyword

Cant render extrafield in category item view

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157527 by Artonezero Limited
Cant render extrafield in category item view was created by Artonezero Limited
Hi - I'm trying to create a simple table view in category items including the title and some, but not all of the extra fields as part of the table row for each K2 article.

I've tried many solutions to display 2 of 4 extra fields category_item.php but every time i get the following :

Trying to get property of non-object

Extra field is called Length and Alias is Length

I add the following into category_item.php inside my template folder ( its int he correct place as the rest of the page is rendering correctly):
$this->item->extra_fields->Length->value;

also tried:
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{    
$extrafields[$item->id] = $item->value;
}   
?>
// Render a specific extrafield
<td>
	<?php echo $extrafields[1]; ?>	 
</td>
<td>
	<?php echo $extrafields[4]; ?>
</td>

This time the error is

Invalid argument supplied for foreach().... Undefined offset:1.... Undefined offset:4....

Has it changed since 2.7.1 or something else i need to add / change?

I've loooked at github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L104-L109

and tried various other methods seen in forum answers, but always get this error message and no output. there is a value inside the
Any help appreciated.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157536 by Krikor Boghossian
Replied by Krikor Boghossian on topic Cant render extrafield in category item view
$this->item->extra_fields->Length->value;
should work.

Make sure that it is length and not Length.

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

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

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157539 by Artonezero Limited
Replied by Artonezero Limited on topic Cant render extrafield in category item view
Hi Krikor,

Thansk for replying quickly. Nothing is output in the table. Here's the category_item.php in full, maybe i've removed something crucial?
// no direct access
<?php defined('_JEXEC') or die;

// Define default image size (do not change)
K2HelperUtilities::setDefaultImage($this->item, 'itemlist', $this->params);

?>

<!-- Start K2 Item Layout -->
	

	  <?php if($this->item->params->get('catItemTitle')): ?>
	  <!-- Item title -->
	  <td class="catItemTitle">

	  	<?php if ($this->item->params->get('catItemTitleLinked')): ?>
			<a href="<?php echo $this->item->link; ?>">
	  		<?php echo $this->item->title; ?>
	  	</a>
	  	<?php else: ?>
	  	<?php echo $this->item->title; ?>
	  	<?php endif; ?>

	  	<?php if($this->item->params->get('catItemFeaturedNotice') && $this->item->featured): ?>
	  	<!-- Featured flag -->
	  	<span>
		  	<sup>
		  		<?php echo JText::_('K2_FEATURED'); ?>
		  	</sup>
	  	</span>
	  	<?php endif; ?>
	  </td>
	  <?php endif; ?>

<td>
	<?php echo $this->item->extra_fields->Length->value; ?>	 
</td>
<td>
	<?php echo $this->item->extra_fields->Weight->value; ?>	
</td>
<?php if($this->item->params->get('catItemIntroText')): ?>
	  <!-- Summary -->
	  <td>
	  	<?php echo $this->item->introtext; ?>
	  </td>
<?php endif; ?>
<!-- End K2 Item Layout -->

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

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157541 by Artonezero Limited
Replied by Artonezero Limited on topic Cant render extrafield in category item view
I also tried renaming the alias's to lowercase and referneced them correctly in lowercase in the code too. Also tried different fields and still no output. error message is:
Trying to get property of non-object

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157543 by Krikor Boghossian
Replied by Krikor Boghossian on topic Cant render extrafield in category item view
What does this code produce?
<?php var_dump($this->item->extra_fields); ?>

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

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

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157545 by Artonezero Limited
Replied by Artonezero Limited on topic Cant render extrafield in category item view
Here's the output:
string(411) "[{"id":"1","value":"10' 3\" - 3.11m"},{"id":"2","value":"4' 0\" - 1.22m"},{"id":"3","value":"-"},{"id":"4","value":"45"},{"id":"5","value":"54 sq ft - 5.2 sq m"},{"id":"6","value":"150-220 hours"},{"id":"7","value":["Suggested Hardware Lists","#","same"]},{"id":"8","value":["Buy the plan","#","same"]},{"id":"9","value":["Download a study plan","#","same"]},{"id":"10","value":["Buy a study plan","#","same"]}]"

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

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157546 by Artonezero Limited
Replied by Artonezero Limited on topic Cant render extrafield in category item view
If i add that line of code to the item.php file i get the following:
array(10) { [0]=> object(stdClass)#605 (8) { ["id"]=> string(1) "1" ["name"]=> string(6) "Length" ["value"]=> string(14) "10' 3" - 3.11m" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "1" ["alias"]=> string(6) "length" } [1]=> object(stdClass)#604 (8) { ["id"]=> string(1) "2" ["name"]=> string(4) "Beam" ["value"]=> string(13) "4' 0" - 1.22m" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "2" ["alias"]=> string(4) "Beam" } [2]=> object(stdClass)#651 (8) { ["id"]=> string(1) "3" ["name"]=> string(5) "Draft" ["value"]=> string(1) "-" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "3" ["alias"]=> string(5) "Draft" } [3]=> object(stdClass)#652 (8) { ["id"]=> string(1) "4" ["name"]=> string(11) "Weight (kg)" ["value"]=> string(2) "45" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "4" ["alias"]=> string(8) "weightkg" } [4]=> object(stdClass)#653 (8) { ["id"]=> string(1) "5" ["name"]=> string(9) "Sail Area" ["value"]=> string(19) "54 sq ft - 5.2 sq m" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "5" ["alias"]=> string(8) "SailArea" } [5]=> object(stdClass)#654 (8) { ["id"]=> string(1) "6" ["name"]=> string(24) "Time to build (estimate)" ["value"]=> string(13) "150-220 hours" ["type"]=> string(9) "textfield" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "6" ["alias"]=> string(19) "Timetobuildestimate" } [6]=> object(stdClass)#655 (11) { ["id"]=> string(1) "7" ["name"]=> string(24) "Suggested Hardware Lists" ["value"]=> string(41) "Suggested Hardware Lists" ["type"]=> string(4) "link" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "7" ["url"]=> string(1) "#" ["text"]=> string(24) "Suggested Hardware Lists" ["attributes"]=> string(0) "" ["alias"]=> string(21) "SuggstedHardwareLists" } [7]=> object(stdClass)#656 (11) { ["id"]=> string(1) "8" ["name"]=> string(12) "Buy the plan" ["value"]=> string(29) "Buy the plan" ["type"]=> string(4) "link" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "8" ["url"]=> string(1) "#" ["text"]=> string(12) "Buy the plan" ["attributes"]=> string(0) "" ["alias"]=> string(10) "Buytheplan" } [8]=> object(stdClass)#657 (11) { ["id"]=> string(1) "9" ["name"]=> string(21) "Download a study plan" ["value"]=> string(38) "Download a study plan" ["type"]=> string(4) "link" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(1) "9" ["url"]=> string(1) "#" ["text"]=> string(21) "Download a study plan" ["attributes"]=> string(0) "" ["alias"]=> string(18) "Downloadastudyplan" } [9]=> object(stdClass)#658 (11) { ["id"]=> string(2) "10" ["name"]=> string(16) "Buy a study plan" ["value"]=> string(33) "Buy a study plan" ["type"]=> string(4) "link" ["group"]=> string(1) "1" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["url"]=> string(1) "#" ["text"]=> string(16) "Buy a study plan" ["attributes"]=> string(0) "" ["alias"]=> string(13) "Buyastudyplan" } }

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157566 by Krikor Boghossian
Replied by Krikor Boghossian on topic Cant render extrafield in category item view
The object is correct in the item, but not in the category_item.php
The alias is not present.
The alias is present in the category as well.

I assume you are using K2's latest version. Are you using any other K2 related extensions?

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

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

  • Artonezero Limited
  • Artonezero Limited's Avatar Topic Author
  • Offline
  • New Member
More
7 years 8 months ago #157577 by Artonezero Limited
Replied by Artonezero Limited on topic Cant render extrafield in category item view
Yes latest i believe - 2.7.1 - i can try reinstalling?

No other extensions on the entire site. Just Joomla a basic custom template and K2 presently.

It's a staging / development site.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157582 by Krikor Boghossian
Replied by Krikor Boghossian on topic Cant render extrafield in category item view
Can you try the DEV version?
github.com/getk2/k2

Let me know how it went.

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