Keyword

K2 Extra Fields Image Tag Src Extract

  • Design
  • Design's Avatar Topic Author
  • Offline
  • New Member
More
3 years 2 months ago - 3 years 2 months ago #148163 by Design
Design replied the topic: K2 Extra Fields Image Tag Src Extract

Krikor wrote: Can you post your solution for reference?


Sure.

I combined all of this in the php header of item.php.
//convertArray Extra Fields to use ids as key
    $extrafields = array();
    foreach($this->item->extra_fields as $item)
    {    
        $extrafields[$item->id] = $item->value;
    }

And this part is for actually stripping the IMG tag of the Image field I wanted, which had ID 28 (Still in header):
$icon = $extrafields[28];
$icon = preg_replace('/<img src="/',"",$icon);
$icon = substr($icon, 0, strpos($icon, '"'));

Later on, just declare the new variable $icon:
<div class="icon" style="background-image: url('<?php echo $icon; ?>')"></div>
Last Edit: 3 years 2 months ago by Design.

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

More
3 years 2 months ago #148229 by Lefteris
Lefteris replied the topic: K2 Extra Fields Image Tag Src Extract
Thanks for sharing this.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
1 week 3 days ago #170491 by Michael Rosa
Michael Rosa replied the topic: K2 Extra Fields Image Tag Src Extract
If your Extra field image name is something other then Image like in my case it's calle List iamge the above regex doesn't work.

This should work better, at least for me it does.
$var = $this->item->extraFields->EXTRAFIELDALIASHERE->value ;
$var = preg_replace('/<img src="(.*?)".*?\/>/', '$1', $var);

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
1 week 2 days ago #170501 by Fotis
Fotis replied the topic: K2 Extra Fields Image Tag Src Extract
I think we can add a "$this->item->extraFields->EXTRAFIELDALIASHERE->rawValue" output to only grab the image path. We already have this option for dates either way.


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

Moderators: william white