Keyword

SOLVED: Extrafields with error.

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 9 months ago - 11 years 7 months ago #108474 by Johann Scharfetter
SOLVED: Extrafields with error. was created by Johann Scharfetter
Hello,

I tried to add extra fields to a certain position in K2 item view in a new website. (not de predefined view in a table)

What I did:
1.) In the Category-settings: the correct extra fields group is associated (Associated "Extra Fields Group")

2.) I added this code to item.php
Log in  or Create an account to join the conversation.

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 8 months ago #108475 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Extrafields with error.
Hello,

I am still struggling with this error. Please, do someone can give me a hint?

The live site is: www.monpetitpot.es/index.php?option=com_k2&view=item&id=8:jab%C3%B3n-de-rosa-para-la-cara&Itemid=247

Thank you!

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

More
11 years 8 months ago #108476 by Daniel Hristov
Replied by Daniel Hristov on topic Re: Extrafields with error.
Hi!

I do not know the version og K2 you use, but if is 2.6.x, you shoul write:

<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != '' && $extraField->id == 1): ?> <!-- replace 1 with your extrafield ID -->
<?php echo $extraField->name'.': '.'$extraField->value; ?> <!-- style it as you wish ->>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>


And that is all!

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 8 months ago - 11 years 8 months ago #108477 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Extrafields with error.
Hi Daniel,

thank you for your answer.

When I copy your code to item.php follwowing error appears in frontend. (I have an extra field with ID=1)
Log in  or Create an account to join the conversation.

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago - 11 years 7 months ago #108478 by Johann Scharfetter
Replied by Johann Scharfetter on topic Re: Extra fields for 2.6.2+ - How to?
Hi Jean-Philippe,

thank you for your answer,

I repost your answer, because it seem to have disappeared.

you need to modify your code:

put :
<?php echo $extraField->name .': '. $extraField->value; ?> <!-- style it as you wish ->>

instead of :
<?php echo $extraField->name '.': '.'$extraField->value; ?> <!-- style it as you wish ->>

Best regards


1.)
I added this code to item.php.
the error disappeared, but the content of the extra field is not shown ether. I tried several extrafield IDs, without success.
Log in  or Create an account to join the conversation.

More
11 years 7 months ago #108479 by jean-philippe
Replied by jean-philippe on topic Re: Extra fields for 2.6.2+ - How to?
Hi scharfet,

for me this code works perfectly
					
Emond, Jean-Philippe

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

  • Johann Scharfetter
  • Johann Scharfetter's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 7 months ago - 11 years 7 months ago #108480 by Johann Scharfetter
Replied by Johann Scharfetter on topic SOLVED: Extra fields for 2.6.2+ - How to?
Hi Jean-Philippe,

it is working now. The error was that "show extra fields" was disabled ;) Sorry.

For others who wants to know how to use "Extra Fields" in a personalized way in "Item view".
In "Category" > "Item View Options " > "Extra Fields" > it is necesary to put "Show".
The extra fields will be displayed also in the standard way (in a table). This code need to be deleted forom item.php.

At the beginning of the item.php place following code.
Log in  or Create an account to join the conversation.