Keyword

[SOLVED] Returning the Value of an Extra_Field In category_item View

  • quebecguitare
  • quebecguitare's Avatar Topic Author
  • Offline
  • Senior Member
More
9 years 2 months ago - 9 years 2 months ago #136439 by quebecguitare
Hello, thank you for reading this post.

I am trying to return the value of the extra_field_13 of an item, right in the header of the category_item view under the title.

This doesn't seems to work, I get an Invalid argument supplied for foreach.

Please help!

Regards

<header>
<?php if(isset($this->item->editLink)): ?>
<a class="catItemEditLink modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php echo $this->item->editLink; ?>"> <?php echo JText::_('K2_EDIT_ITEM'); ?> </a>
<?php endif; ?>
<h2>

<!-- Call to prepare extra fields -->
<?php
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>

<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>"><?php echo $this->item->title; ?></a></br>
<a href="<?php echo $this->item->link; ?>"><?php echo $extrafields[13]; ?></a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>
<?php if($this->item->params->get('catItemFeaturedNotice') && $this->item->featured): ?>
<sup><?php echo JText::_('K2_FEATURED'); ?></sup>
<?php endif; ?>
</h2>
</header>


Thank you for your time!
Last edit: 9 years 2 months ago by quebecguitare.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 months ago #136444 by Krikor Boghossian
Replied by Krikor Boghossian on topic Returning the Value of an Extra_Field In category_item View
You can render specific extrafields like this:
$this->item->extraFields->EXTRAFIELDALIASHERE->name
$this->item->extraFields->EXTRAFIELDALIASHERE->value 
(Check where $item and $this->item has been used).

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

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

More
9 years 2 months ago - 9 years 2 months ago #136490 by pascal95223
Hi qGuitare,

I have same problem.

It's not problem to see it on items but it's impossible on category_item.

You find solution?

Edit: And name work but value dosn't work. And i try with other template, i check if Extra fields are on.

Thank's.
Last edit: 9 years 2 months ago by pascal95223. Reason: add info

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 months ago #136507 by Krikor Boghossian
Replied by Krikor Boghossian on topic Returning the Value of an Extra_Field In category_item View
Double check your category's settings to see if the extrafields are enabled.

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

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

More
9 years 2 months ago #136523 by pascal95223
I check it and extrafields are display. But i want to use it by myself. With value and name. To place url extrafields value on link of picture for example.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 months ago #136529 by Krikor Boghossian
Replied by Krikor Boghossian on topic Returning the Value of an Extra_Field In category_item View
What is the code you have written at this point?

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

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

More
9 years 2 months ago #136530 by pascal95223
I try this:
 <?php echo $this->item->extraFields->test->name ;?><?php echo $extraField[4]->value;?><br/>
    <?php echo $this->item->extraFields->test->value ;?>
    <?php echo ($item->extraField->test->value); ?>
    <?php echo isset($item->extraFields->test->name); ?>
	
    
<?php    echo $this->item->extraFields->test->value; ?>
<?php echo  $item->extraFields->test->value; ?> 
 <?php echo $extrafields['4']->name; ?>

And i check with in on top:
$k2obj = new K2ModelItem(); $fields = $k2obj->getItemExtraFields($this->item->extra_fields, $this->item);

So all extra_fields name are show, but we can't see anything about value.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 months ago #136539 by Krikor Boghossian
Replied by Krikor Boghossian on topic Returning the Value of an Extra_Field In category_item View
try
var_dump($this->item->extraFields->test);

Make sure you have not made a typo in the field's alias.

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

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

More
9 years 2 months ago #136562 by pascal95223
Result:
object(stdClass)#6909 (8) { ["id"]=> string(2) "10" ["name"]=> string(25) "test" ["value"]=> NULL ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(1) "6" ["alias"]=> string(23) "test" }

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 2 months ago #136582 by Krikor Boghossian
Replied by Krikor Boghossian on topic Returning the Value of an Extra_Field In category_item View
It appears that this field is present but it is empty (["value"]=> NULL).
Enter a value and try again. It also better if you check if the extrafield has a value before rendering it.
<?php if( isset($this->item->extraFields->test->value)): 
// echo the field
else: 
//no field echo sth else
endif;
?>

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