COMMUNITY FORUM
Getting the image URL from the image ExtraField Value
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
Less
More
10 years 4 months ago #135945
by Kelsey Brookes
Getting the image URL from the image ExtraField Value was created 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
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
-
Topic Author
- Offline
- Elite Member
10 years 4 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; ?>" />
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 4 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.
Please Log in or Create an account to join the conversation.
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
10 years 4 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.
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 4 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.
Please Log in or Create an account to join the conversation.
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
10 years 4 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.
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 4 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.
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.
Please Log in or Create an account to join the conversation.
- Kelsey Brookes
-
Topic Author
- Offline
- Elite Member
10 years 4 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 4 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 :)
Please Log in or Create an account to join the conversation.