Keyword

Getting the image URL from the image ExtraField Value

  • Kelsey Brookes
  • Kelsey Brookes's Avatar Topic Author
  • Offline
  • Elite Member
More
9 years 8 months ago #135945 by Kelsey Brookes
Is it possible to just get the URL of the image in an image extrafield?

I have a use-case where it'll make the client's life easier to be able to select an image using image field on the backend, but the formatting on the front end needs changes to the img element. It'd be better to simply output the image URL and construct the rest of the img element in the template.

Is it possible?

Regards, Kelsey

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

  • Kelsey Brookes
  • Kelsey Brookes's Avatar Topic Author
  • Offline
  • Elite Member
More
9 years 8 months ago #135946 by Kelsey Brookes
Replied by Kelsey Brookes on topic Getting the image URL from the image ExtraField Value
I found the answer for this here, however the regex used to remove the trailing info isn't great:

getk2.org/documentation/tips-a-tricks/1129-extra-field-image-type-as-link

Here's my solution:

<?php
$topicVid = $this->item->extraFields->TopicSummaryVideoImage->value;
$topicVid = preg_replace('/<img src="/',"",$topicVid);
$topicVid = preg_replace('/" alt="[a-z,A-z,\s]+"\s\/\>/',"",$topicVid);
//echo '<a href="' . $topicVid . "TextOfLink" . "</a>" ;
//echo '<img class="youtube img-responsive" src="' . $topicVid . "TextOfLink" . ">" ;
?>
<img class="youtube img-responsive" rel="<?php echo $this->item->extraFields->TopicSummaryVideoID->value; ?>" src="<?php echo $topicVid; ?>" />

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 8 months ago #135955 by Krikor Boghossian
Replied by Krikor Boghossian on topic Getting the image URL from the image ExtraField Value
If you want to use the src in let's say a css background, you can use JS as well.

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

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

  • Kelsey Brookes
  • Kelsey Brookes's Avatar Topic Author
  • Offline
  • Elite Member
More
9 years 8 months ago #135982 by Kelsey Brookes
Replied by Kelsey Brookes on topic Getting the image URL from the image ExtraField Value
The image extrafield is very useful from the backend, as it's easy for clients to select the image they require.

The output is very rigid however.

I still wanted an img element, but as you can see from my example, I wanted to extend the img element attributes to make use of the Bootstrap Modal YouTube library.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 8 months ago #136024 by Krikor Boghossian
Replied by Krikor Boghossian on topic Getting the image URL from the image ExtraField Value
You can use the method you found or you can add classes using jQuery's addClass() function.

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

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

  • Kelsey Brookes
  • Kelsey Brookes's Avatar Topic Author
  • Offline
  • Elite Member
More
9 years 8 months ago #136030 by Kelsey Brookes
Replied by Kelsey Brookes on topic Getting the image URL from the image ExtraField Value
True, but would I have been able to add the rel='' attribute as well? I could have also done it with ReReplacer, but I was finding scoping to be an issue - adding it specifically to just the specific images I was after was proving difficult and I wanted a foolproof method of doing it just in the override.

I've seen some discussion about introducing a 'file' type of extra field that would allow user selection in the editor, but present as a plain URL on output. That would be massively useful.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 8 months ago #136034 by Krikor Boghossian
Replied by Krikor Boghossian on topic Getting the image URL from the image ExtraField Value
Sure, the attr() function can be used in jQuery or you add it in the preg_replace funtion.
Both of these methods should be done in the overrides.
Since the preg_replace provides you with a clean url you can store it in a variable to echo it using a different markup if you do not want to use JS.

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

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

  • Kelsey Brookes
  • Kelsey Brookes's Avatar Topic Author
  • Offline
  • Elite Member
More
9 years 8 months ago #136037 by Kelsey Brookes
Replied by Kelsey Brookes on topic Getting the image URL from the image ExtraField Value
Nice! Thank you!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 8 months ago #136040 by Krikor Boghossian
Replied by Krikor Boghossian on topic Getting the image URL from the image ExtraField Value
You 're welcome Kelsey :)

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