This question already has answers here:
How can I display the image from the related entry for each entry in craft CMS and twig?
(2 answers)
Closed 10 months ago.
I'm new to using Craft CMS and trying to successfully make an image display.
I have set up a field with the handle heroImage and this is the code I have within the template.
{% set image = entry.heroImage.one() %}
<div>
<img src="{{ image.getUrl }}">
</div>
However, the image is not displaying in the browser.
I think you forgot to add parenthesis after getUrl as it was a function (method). You can use below code for that.
{% set image = entry.heroImage.one() %}
<div>
<img src="{{ image.getUrl() }}">
</div>
Users encountering this may want to check folder permissions. I encountered this in a site migration situation.
Try this
<img src="https://dev-craft3-384fa3039dfb.hyperlane.co/uploads/scren1.png" referrerpolicy="no-referrer" alt="ALI TEST LIVE LINK" />
Related
I have two lists. One scrapes the link text from Google News and the other contains the link.
return render_template('news.html', link_text=link_t, link_addr=links_h)
How do I make clickable headlines in Jinja. I have done this.
{%for item in range(0, 30)%}
<div class="border">
<li><a href=" {{ link_addr[i] }}" >{{ link_text[i] }}</a></li>
</div>
{%endfor%}
I know this won't work for the href part(I don't know the correct format). It makes the headlines appear neatly. However I don't know how to link the headline to the matching href. They need to be in a <div> inside the <li> element.Please Help.
Tried different variations and this one worked. Strange,I thought I already tried this.
<li><a href=" {{ link_addr[i] }}" >{{ link_text[i] }}</a></li>
This gives clickable headlines perfectly.
I am using django-el-pagination package and trying to implement digg-style pagination on my home template. I am displaying it with..
{% get_pages %}
{{ pages.get_rendered }}
and it is showing like this <1234567> which is fine but
I want to add some css or class to change the way it look.
If you have any other way to achieve this. Please suggest..
please tell how can I customize it.
You can change it to make it looks something like this or like whatever you want:
Here is an example:
{% get_pages %}
<div class="pagination">
{% for page in pages %}
<li class="page-item">{{ page.number }}</li>
{% endfor %}
</div>
You can check the documentation here: https://django-el-pagination.readthedocs.io/en/latest/templatetags_reference.html#get-pages to check all the available options for get_pages
I am trying to add buttons to my Spartacus storefront.
The problem that is preventing me to progress ahead is:
1)If I generate new button angular component, using Angular, should it be mentioned inside the
tag or outside of that?
2)Should it be rendered in a different way as first?
Check out this repo and the corresponding stackblitz project. The easiest way add new buttons would be to place it in reference to an existing standard component using the outlets. Essentially, you could do some like the following, placing your new angular component app-custom-component before the ExistingComponent.
<ng-template cxOutletRef="ExistingComponent" cxOutletPos="before">
<app-custom-component></app-custom-component>
</ng-template>
Can you describe the problem more clearly? As much as I understood you are looking for below kind of code. For code check this link Spartacus Product Page
<div class="row">
<div class="col-md-6">
<button
class="btn btn-block btn-action"
(click)="addAddressButtonHandle()"
>
{{ 'addressBook.addNewAddress' | cxTranslate }}
</button>
</div>
</div>
I am using Django 1.10. Technically this post is regarding Django-registration-redux but SO wouldnt let me create a new tag to post the question. Django-registration-redux doesnt see the registration templates. I copied all the templates into a folder called "registration" inside of my templates folder. I dont get an error though. For example, when I go to /accounts/register it renders some form but it isn't the one from my templates/register folder. Im not sure what I am doing wrong. I have even gone as far as to delete the templates/registration folder entirely and I dont even get an error. I read some similar posts where people had to move the registration to the top of the installed apps so it wouldnt use the admin forms which I tried and didnt help. So far nothing has changed. All the templates do extend base.
So Im guessing I have configured something wrong. It's weird. All the functionality is there but its just not using my templates. Sorry if its a dumb question but I would appreciate some help!
pip freeze
Django==1.10
django-crispy-forms==1.6.0
django-registration-redux==1.4
INSTALLED_APPS = [
'registration',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# third party
'crispy_forms',
# my apps
'todo',
]
# Django registration redux settings
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = True
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/' # The page you want users to arrive at after they successful log in
LOGIN_URL = '/accounts/login/'
SITE_ID = 1
Here is my /templates/registration/registration_form.html
{% extends "base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<div class='row'>
<div class='col-sm-6 col-sm-offset-3'>
<h1>Register for free!</h1>
<form method="post" action=".">
{% csrf_token %}
{{ form|crispy }}
<input class='btn btn-block btn-primary' type="submit" value="{% trans 'Join' %}" />
</form>
</div>
</div>
<hr/>
<div class='row'>
<div class='col-sm-6 col-sm-offset-3 text-align-center'>
<p>Need to Login?</p>
</div>
</div>
{% endblock %}
this is a screenshot showing the form I see at accounts/register
In settings.py you have to place your app above the 'registration' app. It seems the order the apps are listed in the settings.py file determines which templates are being used.
Next time try making a directory relating to your app's name in the app templates folder. For instance, if you have an app called "register" call the folder "register" in the templates folder of your app and then put all your templates in there. This would prevent templates named index.html in both app templates folder and the main project templates folder from conflict with each other.
In Grav which uses twig as a templating engine, I have:
<ul>
{% for page in taxonomy.findTaxonomy({'tag': 'shell'}) %}
<li>{{ page.title }}</li>
{% endfor %}
</ul>
to get all pages that have tag set to shell -
However, page.title renders fine, but page.url gives
%7B%7B%20page.url%20%7D%7D?
If I put page.url in place where page.title is, so between <a></a> tags,
everything works fine? Is this some kind of bug?
EDIT
Exactly the same as described here: https://github.com/erusev/parsedown/issues/266
FOUND SOLUTION
Luckily Grav has an option to process twig first then markdown.
By setting twig_first: true into page meta, I was able to solve the problem.
So the culprit is markdown processor.
just print the object using {{var_dump(page)}}
then you can see the getter method or array value of the object.
Here is my solution for your problem {{ page.route }}
It is working for me!
Hope this helps someone.