- Posts: 72
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Returning the Value of an Extra_Field In category_item View
[SOLVED] Returning the Value of an Extra_Field In category_item View
- quebecguitare
- Topic Author
- Offline
- Senior Member
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!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
$this->item->extraFields->EXTRAFIELDALIASHERE->name
$this->item->extraFields->EXTRAFIELDALIASHERE->value
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- pascal95223
- Offline
- New Member
- Posts: 9
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.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- pascal95223
- Offline
- New Member
- Posts: 9
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- pascal95223
- Offline
- New Member
- Posts: 9
<?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
- Offline
- Platinum Member
- Posts: 15920
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.
- pascal95223
- Offline
- New Member
- Posts: 9
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
- Offline
- Platinum Member
- Posts: 15920
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.
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Returning the Value of an Extra_Field In category_item View