- 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.
- pascal95223
-
- Offline
- New Member
- Posts: 9
<?php if( isset($this->item->extraFields->test->value)):
echo ok;
else:
echo notok;
endif;
?>
I see notok on category_item.php and i see ok on item.php
And var_dump is different on item.php
object(stdClass)#562 (8) { ["id"]=> string(2) "21" ["name"]=> string(4) "test" ["value"]=> string(14) "OK TEST OK" ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["alias"]=> string(4) "test" }
It's very strange.
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
On category_item.php
object(stdClass)#466 (8) { ["id"]=> string(2) "21" ["name"]=> string(4) "test" ["value"]=> NULL ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["alias"]=> string(4) "test" }
On item.php
object(stdClass)#562 (8) { ["id"]=> string(2) "21" ["name"]=> string(4) "test" ["value"]=> string(14) "CEST OK A MORT" ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["alias"]=> string(4) "test" }
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
object(stdClass)#6909 (8) { ["id"]=> string(2) "10" ["name"]=> string(25) "test" ["value"]=> NULL ...
Which is a different field within the same group. Remove these fields and start over with a new distinct 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
On category_item.php
object(stdClass)#466 (8) { ["id"]=> string(2) "21" ["name"]=> string(4) "test" ["value"]=> NULL ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["alias"]=> string(4) "test" }
On item.php
object(stdClass)#562 (8) { ["id"]=> string(2) "21" ["name"]=> string(4) "test" ["value"]=> string(14) "CEST OK A MORT" ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "10" ["alias"]=> string(4) "test" }
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
I try this and it's same.
Category_item.php
object(stdClass)#467 (8) { ["id"]=> string(2) "22" ["name"]=> string(6) "krikor" ["value"]=> NULL ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "11" ["alias"]=> string(6) "krikor" }
item.php
object(stdClass)#756 (8) { ["id"]=> string(2) "22" ["name"]=> string(6) "krikor" ["value"]=> string(3) "sdq" ["type"]=> string(9) "textfield" ["group"]=> string(1) "2" ["published"]=> string(1) "1" ["ordering"]=> string(2) "11" ["alias"]=> string(6) "krikor" }
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.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
You should move this site to a dev enviroment, update K2 to 2.6.9 and update all your extensions.
If this does not work then try disabling these extensions one by one ( starting with K2 plugins ) until you find the culprit.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- quebecguitare
-
Topic Author
- Offline
- Senior Member
- Posts: 72
Content - Pagebreak - MyJspace
Site Plugin 2.4.2 26/08/2014 Bernard Saulme content 10127
Thank you Krikor, way to go!
Best Regards.
Thank you for your time!
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