I have the image in: src/WebBundle/img/img2.jpg
Im trying this but donĀ“t works:
<img src="{{ asset('WebBundle/img/img2.jpg') }}" />
Image of routes
Thank you for the patience
Better to user assets.
{% image '#AppBundle/Resources/public/images/example.jpg' %}
<img src="{{ asset_url }}" alt="Example" />
{% endimage %}
In your case just change image url to avoid any url problem.
Related
I am trying to make a little website with django when I ran into a problem:
I have a site where I want to look at a post in detail, but not every post has an image attribute - so I am getting an error when I try to display images, since some arent existent.
So the solution would be to check if an image is given, but... How do I do that?
I tried something like this but it did not work:
</div>
<p>{{ object.content }}</p>
{% if object.image.url == True %} <!-- In no case an image is displayed -->
<p>
<img src="{{ object.image.url }}">
</p>
{% endif %}
</div>
You should check the truthiness object.image attribute, not its URL, so:
{% if object.image %}
<p><img src="{{ object.image.url }}"></p>
{% endif %}
I know that it has to do womething with category.twig which is in /catalog/view/theme/YOURTHEME/template/product/category.twig
I tried to do whatever instructions I found in forums.
I tried this and I tried that
I tried to refresh Cache.
I need more help. What I am doing wrong? Or maybe these instructions that I tried are wrong?
Seems like you are doing everything right. Make sure that in /catalog/view/theme/YOURTHEME/template/product/category.twig YOURTHEME is actually your current theme. From the tutorial for thumb and description take this code
{% if thumb or description %}
<div class="row"> {% if thumb %}
<div class="col-sm-2"><img src="{{ thumb }}" alt="{{ heading_title }}" title="{{ heading_title }}" class="img-thumbnail" /></div>
{% endif %}
{% if description %}
<div class="col-sm-10">{{ description }}</div>
{% endif %}
</div>
<hr>
{% endif %}
Or only for description take
{% if description %}
<div class="col-sm-10">{{ description }}</div>
{% endif %}
And replace it anywhere in this template file (almost everywhere actually).
The most important is to clear twig cache. On howto do that i have described the process in the other article earlier, please read
https://stackoverflow.com/a/61524855/3187127
After that - click Ctrl F5 if you are using Chrome or Firefox (or other combination in your browser which reloads page with cache cleaning) while you are on a category page.
I want to download an image file from HTML inside my Django app this is my code in the template.
{% for pic in pics %}
<a href="{{ pic.image.url }}" download>
<img src="{{ pic.image.url }}">
</a>
{% endfor %}
The images are rendered and everything else is working fine. When I click on the image, it opens in fullscreen instead of downloading. I am using chrome. What am I doing Wrong?
Am creating my first Jekyll (using version 4.0.0) powered site. Problem is the variables in Front Matter are not recognized.
HTML in _includes (writing-post-featured-image.html)
<figure>
<img class="feat-img" src="{{ site.baseurl }}/assets/images/{{ include.images }}" alt="{{ include.alt | default: 'lorem ipsum' }}" />
<figcaption>{{ include.caption }}</figcaption>
</figure>
In _layout having layout for text based post pages (writings-post.html)
{% include writing-post-featured-image.html image=post.featured-image alt=post.featured-image-alt %}
Last, in .md file (under _posts) the following Front Matter
layout: writings-post
title: my title
permalink: /writings/:title
featured-image: photo.jpg
featured-image-alt: about photo
caption: photo caption
Output is empty
<figure>
<img class="feat-img" src="" alt="lorem ipsum" />
<figcaption></figcaption>
</figure>
Please help understanding why so. Thanks in advance.
Your syntax is incorrect.
1.) As your passing variables from your page, your include tag should look like this :
{% include writing-post-featured-image.html
image=page.featured-image
alt=page.featured-image-alt
caption=page.caption %}
2.) In your include you have a syntax problem with include.images that should be include.image.
Note : as you're passing existing variables (not computed ones), you can skip passing them to your include, because from within an include you can see page's variables.
{% include writing-post-featured-image.html %}
And your include :
<figure>
<img class="feat-img"
src="{{ site.baseurl }}/assets/images/{{ page.featured-image }}"
alt="{{ page.featured-image | default: 'lorem ipsum' }}" />
<figcaption>{{ page.caption }}</figcaption>
</figure>
The correct syntax on the page of the post is:
{% include writing-post-featured-image.html image=page.featured-image alt=page.featured-image-alt %}
Note the page. syntax, instead of the post. syntax. However, when you have a loop in your layout, you can use this:
{% for post in site.posts %}
{% include writing-post-featured-image.html image=post.featured-image alt=post.featured-image-alt %}
{% endfor %}
I'm just learning the basics of django and jinja. I've extended my header file and now I want to add an image to the page, but I don't know the jinja syntax for doing that. Please assist.
{% extends "media/header.html" %}
{% block content %}
This is where I would like to insert my image.
{% endblock %}
Just use html img tag for that. If you pass your image in context as variable;
{% extends "media/header.html" %}
{% block content %}
<img src="{{ variable }}" alt="image alt text" />
{% endblock %}
If you just have static path;
{% extends "media/header.html" %}
{% block content %}
<img src="{{ static('path/to/image.png') }}" alt="image alt text" />
{% endblock %}
May be this is too late to reply, but this is how I use for rendering images using jinja syntax. I have successfully rendered images on pdf from html.
<div class="img-div" style="background-image: url('{{ element.image }}');">
</div>
element.image could be a any resolvable url.