0

I am trying to get owl carousel to respect the image style declared in the manage display setting for the content type. The code I used to output in the node is:

<div class="owl-carousel owl-theme nav-inside box-shadow-custom mt-xl" data-plugin-options='{"items": 1, "margin": 10, "animateOut": "fadeOut", "autoplay": true, "autoplayTimeout": 3000}'>
            <?php foreach($image as $value):?>
                <div>
                    <img src="<?php print file_create_url($value['uri']);?>" class="img-responsive"  alt="">
                </div>
            <?php endforeach;?>
        </div>

This renders the slides all different sizes and makes it have a background and causes it to look bad. Does anyone know how to in a custom node file make it respect the image style that I have created that cause it to scale and crop the images. Thanks.

15
  • Since you are not rendering the field normally, I don't see anywhere that the image style would be respected. What is the value of uri?
    – Kevin
    Sep 12, 2018 at 18:02
  • file_create_url() gives you original file URL, what you can do is then run it by image_style_url($style_name, $path) and you will get what you want.
    – cchen
    Sep 12, 2018 at 18:08
  • I appreciate the help. I am so bad at php. cchen, is there any way you can show me what that would look like?
    – tHaKaREe
    Sep 12, 2018 at 18:15
  • @tHaKaREe something like src="<?php $original_image_url = file_create_url($value['uri']); $styled_image_url = image_style_url($style_name, $original_image_url); print $styled_image_url;?>", you will have to find a way to get the $style_name value though. Does that make sense?
    – cchen
    Sep 12, 2018 at 19:03
  • @tHaKaREe No worries. $style_name is the machine name of the image style you set in the display settings admin page. I think it should be available somewhere when you run dpm($node or something)... Should be pretty similar to how you get the $value['uri'] value.
    – cchen
    Sep 12, 2018 at 19:46

1 Answer 1

0

Just to summarize my comments: 1. after getting the images' URLs, you can run them by image_style_url() function to get the URLs to the styled images. 2. you need to update the foreach() function to include an index such as foreach($image as $key=>$value), and use the $key index to loop through the image array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.