I am trying to preview images which stored inside mybundle/image folder. but i can not get proper image path for view images which name is dynamic.
here is the code.
// inController
$image = $this->get('file_locator');
$path = $image->locate('#AcmeMyBundle/uploads/images/my_img.jpg');
return $this->render('images/myaction.html.twig', array(
'path'=>$path,
));
//in myaction.html.twig
{% image '#SeStorageBundle/uploads/images/'{{ image.name }} %}
<img src="{{ asset_url }}" width="100%" height="100%" alt="my alt of image" class="pull-left">
{% endimage %}
If the link to your image is correct, then try using asset to render the image like this:
<img src ="{{asset(path)}}"/>
Related
I tried to display the image in the blade. but it cant load the image, it displays the image of else statement
<?php $user_image_path = 'images/user_images/' . $userDetails['image']; ?>
#if(!empty($userDetails['image']) && file_exists($user_image_path))
<img src=" {{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
#else
<img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
#endif
I also debug the code above the if statement it fetches the image
<?php $product_image_path = 'images/user_images/' . $userDetails['image']; ?>
<?php
echo "<pre>";
print_r($user_image_path);
die;
?>
From above comments on your question, seems like you are loading the image with no extension. add the image extension
<img src="{{ asset('images/user_images/'.$userDetails['image'].".png") }}" alt="">
or for .jpg
<img src="{{ asset('images/user_images/'.$userDetails['image']).".jpg" }}" alt="">
Try:
<img src="{{ !empty($userDetails['image']) ? asset('images/user_images/'.$userDetails['image']) : asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
It is the second condition of your if condition that doesn't match. The function of file_exists can't locate the the image file. You either have to provide the full path for the file_exists , or remove it:
#if(!empty($userDetails['image']))
<img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
#else
<img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
#endif
Use this code:
<img src=" {{ !empty(asset('images/user_images/'.$userDetails['image'])) ? <img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre"> : <img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre"> }}" alt="Cinque Terre">
#if(!empty($userDetails['image']))
<img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
View the src of image inside inspector. Most of the times it gives us the wrong path instead of public directory.
Secondly, there is space in src. Try to remove and run that.
If asset function doesn't give the public directory path, add ASSETS_URL In .env to /public
I have rendered all my pictures from gallery, but need to get them to slider in my twig file.. is that possible without using any plugin, please???
My code, php:
<?php
$context = Timber::get_context();
$context["post"] = Timber::get_post();
Timber::render( 'pages/single/single-one-collection.twig', $context, CACHE_TIME);
My twig:
{% for picture in post.get_field('oc_gallery') %}
<div class="section" id="section{{ loop.index }}">
<img src="{{ TimberImage(picture).src | resize(400, 266)}}" alt="" />
</div>
{% endfor %}
It's my first time with Timber/Wordpress.
I'm trying to use this plugin with Timber but I can't render any image.
I'm only getting the ids of the images:
{% set images = post.get_field('gallery_images') %} // "47,48"
I also try:
if (isset($post->hero_image) && strlen($post->hero_image)){
$post->hero_image = new TimberImage($post->hero_image);
}
I looked at the documentation
How can I get all the src of my images?
It depends on how or if your field gallery_images is nested further (via ACF).
If it's not nested it should work like this:
{% for image in post.get_field('gallery_images') %}
<img src="{{ TimberImage(image).src }}" alt="" />
{% endfor %}
I want to load pictures dynamically from database.
Here's the table containing the image informations:
Controller code
public function listeproductAction()
{
$em = $this->getDoctrine()->getManager();
$img = $em->getRepository('AppBundle:image')->findAll();
return $this->render('lucky/images.html.twig', array(
'img' => $img ,
));
}
twig code
{% for im in img %}
<img src="{{ asset('/uploads/brochures/' ~ im.getBrochure()) }} ">
{% endfor %}
result
<div class="main-content">
<img src="/uploads/brochures/0fa58c757752ced32d04b57bb7fa0d65.png ">
</div>
The problem is that asset function doesn't find the image.
I try to display an image which is in web/uploads/img
this image has the following name: Screenshot_2014-12-24-23-01-17.png
1/ when doing this, it works perfectly:
<img src="{{ asset('uploads/img/Screenshot_2014-12-24-23-01-17.png') }}" />
2/ when doing the following (the path of the image is in a variable) nothing is displayed :
<img src="{{ asset(array_image_WebPath[t]) }}" />
( with t = 1 and array_image_WebPath[1] = uploads/img/Screenshot_2014-12-24-23-01-17.png)
The fact is that I need to store my webpath of my images in an array. So what is the proper way of doing it?
EDIT: I tried with objects directly doing the following: {% for image in liste_images %} '<'img src="{{ asset(image.webpath)}}"/> {% endfor ‰} AND IT WORKS but I need to use my array to get the right image at the right place.
Go with a for...in:
{% for image in array_image_WebPath %}
<img src="{{ asset(image) }}" />
{% endfor %}
And access the loop index with either loop.index or loop.index0 [respectively 1 and 0 based].