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 %}
Related
In Drupal 7, I used following codes to link to other pages. I have "Service" block and inside that block , I write like this.
<?php
global $base_url;
global $base_path;
$link = $base_url . '/sites/all/themes/bootstrap_business/images';
?>
<div><img alt="" src="<?php print $link?>/customer.png" /></div>
<p> Service</p>
and I save text format with PHP.
But for now Drupal 8, we don't have Text format option "PHP" and also I don't know how to write codes to connect with other page.
Anyone help me please? Thanks.
In drupal 8 you can use hook_preprocess_HOOK() to pass variables to twig files and call your variables like
<header class="main-header">
{{ title_prefix }}
{% if page.header and logged_in %}
{{ page.header }}
{% endif %}
{% if not logged_in %}
<a href="{{ front_page }}" title="{{ 'Home'|t }}" rel="home" id="logo" class="logo">
<img src="{{ base_path }}themes/custom/mytheme/logo-login.png" alt="{{ 'Home'|t }}" />
</a>
<h2 class="login-logo">{{ site_name }}</h2>
{% endif %}
{{ title_suffix }}
</header>
Please see https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates for more details
You can also include other pages using
{# this template is located in templates/layout.html.twig #}
{% extends "layout.html.twig" %}
{# this template is located in templates/user/profile.html.twig #}
{{ include('user/profile.html.twig') }}
See: https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates
In your example, you need to specify your theme directory. Just use:
<img src="/{{ directory }}/images/xyz.jpg">
Here, {{directory }} will resolve to directory of your current theme.
For preparing links to other fields. see above mentioned drupal page
I wanted to display the url of an image from bdd in my file twig I receive an error of the image like the:
this is my bdd :
and my view from twig :
{% extends '#App/layout.html.twig' %}
{% block title %} Illustration {% endblock %}
{% block body %}
<div class="col-md-4 col-md-offset-4 text-center">
<h2> {{ imageFormation.image.nom }}</h2>
<hr>
<img src=" {{ imageFormation.image.url |raw }} "/><br><br>
</div>
{% endblock %}
Can you help me solve my problem please?
i dont know why i cant get the real image.
edit :
/**
* #Route("/formation/{formation}" , name="image")
* #param $image
* #return \Symfony\Component\HttpFoundation\Response
*/
public function imageFormationAction($formation){
$doctrine = $this->container->get('doctrine');
$em = $doctrine->getManager();
$imageRepository = $em->getRepository('AppBundle:Formation');
$imageFormation = $imageRepository->findOneByid($formation);
return $this->render('#App/formation/formationImage.html.twig', array(
'imageFormation' => $imageFormation
));
}
Your image url must be relative to web directory, like this fichier\Mention.jpg, not the image's path in your file system C:\xampp\htdocs\Symfony\MonProjetCv\web\fichier\Mention.jpg.
Save a relative path to your image file in the database (url equal fichier\Mention.jpg), and use asset function in your twig file:
{% extends '#App/layout.html.twig' %}
{% block title %} Illustration {% endblock %}
{% block body %}
<div class="col-md-4 col-md-offset-4 text-center">
<h2> {{ imageFormation.image.nom }}</h2>
<hr>
<img src=" {{ asset(imageFormation.image.url); }} "/><br><br>
</div>
{% endblock %}
Can you please try this way?
<img src='{{ asset("IMAGE_DIRECTORY_PATH/"~ image.url)}}' />
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 am having trouble displaying blob image on my web site, am using symfony 2.7.3...
i tried to encode the blob data in base 64, am able to display the base 64 value but when i embed it in nothing happens bellow is my code.
pls what am in doing wrong ??
controller
$badges = $this->getDoctrine()
->getRepository('AppBundle:News')->findAll();
$images = array();
foreach ($badges as $key => $badge) {
$images[$key] = base64_encode(stream_get_contents($badge->getImage()));
}
return $this->render('default/index.html.twig', array(
'badges' => $badges,
'images' => $images,
));
}
view
{% if badges %}
{% block badge %}
{% for key,badge in badges %}
<div style = "margin:4px;height:100px" class="thumbnail">
<div class="pull-left">
<a href=""><img alt="embeded image"src="data:image/png;base64,{{ images[key] }}" />
</div>
<div style="width:auto" class = "pull-right" >
{{ badge.title }}
</div>
</a>
</div>
{% endfor %}
{% endblock %}
{% endif %}
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].