Keyword

K2 Extra Fields Image Tag Src Extract

  • Design
  • Design's Avatar Topic Author
  • Offline
  • New Member
More
9 years 1 month ago - 9 years 1 month ago #148163 by Design
Replied by Design on 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: 9 years 1 month ago by Design.

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

More
9 years 1 month ago #148229 by Lefteris
Replied by Lefteris on topic K2 Extra Fields Image Tag Src Extract
Thanks for sharing this.

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

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

More
5 years 11 months ago #170491 by Michael Rosa
Replied by Michael Rosa on 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.

More
5 years 11 months ago #170501 by JoomlaWorks
Replied by JoomlaWorks on 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.

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

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

More
5 years 8 months ago - 5 years 8 months ago #171562 by forty
Replied by forty on topic K2 Extra Fields Image Tag Src Extract
Fotis Can you give us all code for that.
I want to use it to change background of div from extrafield.
Thanks
Last edit: 5 years 8 months ago by forty.

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

More
5 years 8 months ago #171571 by JoomlaWorks
Replied by JoomlaWorks on topic K2 Extra Fields Image Tag Src Extract
You need to be more specific.

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

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

More
5 years 7 months ago #171654 by forty
Replied by forty on topic K2 Extra Fields Image Tag Src Extract
Hi, i done it. Thanks!

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

More
5 years 7 months ago #171724 by JoomlaWorks
Replied by JoomlaWorks on topic K2 Extra Fields Image Tag Src Extract
Great!

Fotis / 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