Keyword

How to fetch specific extra field selected val

  • ATHANASIOS ILIOPOULOS
  • ATHANASIOS ILIOPOULOS's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 6 months ago #159068 by ATHANASIOS ILIOPOULOS
How to fetch specific extra field selected val was created by ATHANASIOS ILIOPOULOS
I am trying to make some customizations in my:

administrator\components\com_k2\views\item\tmpl\default.php

file and to print somewhere item's extra field selected values.

In file's code i can see that i can get extra field name and element like:
<?php if (count($this->extraFields)): ?>
    <?php foreach($this->extraFields as $extraField): ?>
        <?php echo $extraField->name; ?>
        <?php echo $extraField->element; ?>
    <?php endforeach; ?>
<?php endif; ?>

however "$extraField->value" does not seem to work. It

I have also tried to access item's extra field values by using:
$extrafields = array();
foreach($item->extra_fields as $item)
{
   $extrafields[$item->id] = $item->value;
}

But "$item->extra_fields" does not seem to work at administrator item.php template of K2.

Any suggestions?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 6 months ago #159123 by Krikor Boghossian
Replied by Krikor Boghossian on topic How to fetch specific extra field selected val
Hello there,

The syntax in the administrator template is a bit different.
$this->row->extra_fields;
is being used.

Depending on the PHP version some str_replace might be needed in order to use json_decode.

Use this snippet as a starting point.
		<?php if($this->row->id): ?>
			<?php $extra_fields = str_replace('&quot;', '"', $this->row->extra_fields); ?>
			<?php var_dump(json_decode($extra_fields)); ?>
		<?php endif; ?>

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

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

  • ATHANASIOS ILIOPOULOS
  • ATHANASIOS ILIOPOULOS's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 6 months ago #159137 by ATHANASIOS ILIOPOULOS
Replied by ATHANASIOS ILIOPOULOS on topic How to fetch specific extra field selected val
Hi Krikor,

thanks for your response, it helped! Resolved it like:
<?php if($this->row->id): ?>
    <?php $extra_fields = str_replace('&quot;', '"', $this->row->extra_fields); ?>
     <?php $extrafields1 = json_decode($extra_fields) ?>
     <?php $sample_type = $extrafields1[5]; ?>
<?php endif; ?>

and then accessing each extra field value like:
$sample_type->value

thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 6 months ago #159138 by Krikor Boghossian
Replied by Krikor Boghossian on topic How to fetch specific extra field selected val
You 're welcome :)

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