I want to apply discount code specific messages on the shopify email templates. I tried the following code, it's showing me error - "Liquid error: Unknown operator = " in the purchase email which I receive.
<div class="row">
<div class="left-column">
{% if discounts %}Discount (code: {{ discounts.first.code }})
</div>
<div class="right-column">
{{ discounts_savings | money_with_currency }}
{% endif %}
</div>
<div class="left-column">
{% for discount in discounts %}
{% if discount.first.code = "DISCODE-2015" %}
Your $50 amazon.com gift card will be send to you soon!
{% endif %}
{% endfor %}
</div>
</div>
You are using =, but it should be ==. See here.
I think you also want discount.code where you have discount.first.code.
Try replacing this line:
{% if discount.first.code = "DISCODE-2015" %}
with this:
{% if discount.code == "DISCODE-2015" %}
Related
a I have been watching a video which uses the following code to show errors.
{% if form.errors %}
<div class="alert alert-danger">
{{form.errors.title.as_text}}
</div>
{% endif %}
But when I use it no errors show
If I use:
{% if form.errors %}
<div class="alert alert-danger">
{% for error in form.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
I get a single word eg. 'email' but the whole error text does not display.
It works fine on the video,
Could anyone tell me what i am doing wrong?
Ok, imaged to get it to work using:
{% if form.errors %}
<div class="alert alert-danger">
{% for key, value in form.errors.items %}
{{ value.as_text }}
{% endfor %}
</div>
{% endif %}
Thanks for your help
what I'm trying to do is bring products pictures and titles from specific collection into my product recommendation module.
This is the module im trying to call my products.
{% if section.settings.show_product_recommendations %}
<div class="product-recommendations"
data-section-type="product-recommendations"
data-components="product-block"
data-url="{{ routes.product_recommendations_url }}?section_id={{ section.id }}&product_id={{ product.id }}&limit=12">
{% if recommendations.performed and recommendations.products_count > 0 %}
<div class="product-recommendations-container product-slider">
<div class="wide-container section-spacing">
<div class="product-list swiper-container" data-products-in-view="{{ section.settings.grid }}">
<h2 class="h2 section-heading" data-cc-animate>
{{ section.settings.title }}
</h2>
<div class="swiper-wrapper" data-normheights=".image" data-normheights-inner="img">
{%- for product in recommendations.products -%}
<div class="swiper-slide">
{% render 'product-block', product: product, product_class: product_class, i: forloop.index, animate: forloop.index, show_vendor: section.settings.show_vendor, hide_swatches: section.settings.hide_swatches %}
</div>
{%- endfor -%}
</div>
<div class="swiper-scrollbar"></div>
{% render 'svg-chevron-left' %}
{% render 'svg-chevron-right' %}
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
So far i did tried something like this. But this code has to be integrated into to code above because what Im trying to do is call specific collection to my recommendations module.
/collections/224916897949 is ID of my collection list and it has multiple products. Instead of using the Shopify panel to add collection I would like to add by liquid.
{% assign collection = collections[section.settings.collection] %}
{% for product in collection.products.224916897949 limit: 12 %}
I am using Flask and I am looping through a table Buyers object in Jinja. What I want to happen is to show a message in the HTML page if there is no data in a specific field Buyers.supplier of the table.
Let's say the table has 5 entries and there are no fields present, what happens in my present code is that I see my message 5 times.
Is there a way to just show the HTML message if all of the fields are empty? Thank you!
main.html
<div class="card-deck">
{# Go through each blog post #}
{% for sched in buyer_sched|sort(attribute='time') %}
{# Only show if a supplier has been matched#}
{% if sched.supplier.company %}
<div class="row pl-3 ml-1">
<p>Show some information</p>
</div>
{% else %}
<p>There is no data</p>
{% endif %}
{% endfor %}
<div />
{% else %}
<p>Please login and register</p>
{% endif %}
{% endblock %}
I answered this in a different (perhaps not so pythonic way).
I basically iterated through the field on the python side and used a counter to count up. If the number was greater than 0, then when I passed the integer into my html template, it wouldn't show the message.
Thank you!
buyer_sched = db.session.query(Buyerschedule).\
filter(Buyerschedule.buyer_id == buyer_id).all()
# Iterate through schedule and if all are none, set
# completed to none
completed = 0
for sched in buyer_sched:
print(f'The schedule name is: {sched.id}')
if sched.supplier_id:
completed = completed + 1
print(f'completed is {completed}')
print(f'completed is equal to {completed}')
You could create a custom jinja filter (https://flask.palletsprojects.com/en/1.1.x/templating/#registering-filters) to check if all are empty before the for loop:
def all_empty(data, key):
return all(not d[key] for d in data)
app.jinja_env.filters['all_empty'] = all_empty
Once registered, you can call that function in your template:
<div class="card-deck" >
{% if data|all_empty('supplier') %}
<p>There is no data</p>
{% else %}
{% for sched in data %}
{% if sched.supplier and sched.supplier.company %}
<div class="row pl-3 ml-1">
<p>{{ sched.supplier.company }}</p>
</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
having trouble nesting the following code. Where am I going wrong?
I just want to have some events show if the day is monday and then within that each event has a number of stars so I want to have another if statement that pulls that amount of stars and displays the correct image.
Here is my code.
<div class="row">
{% for event in site.nottingham_events %}
{% if event.day == "Monday" %}
<div class="event-guide-event">
<img class="event-guide-event--thumbnail" src="/img/thumb.jpg"
alt="">
<h2>{{ event.name }}</h2>
<p>When: {{ event.time }}</p>
<h3>Where: {{ event.bar }}</h3>
<h3>Hosted By: {{ event.brand }}</h3>
{% if event.stars =="3" %}
<img src="/img/events/3-stars.png" alt="Everyone">
{% endif %}
{% if event.stars =="2" %}
<img src="/img/events/2-stars.png" alt="Enthusiasts and
Beginners">
{% endif %}
{% if event.stars =="1" %}
<img src="/img/events/1-star.png" alt="Expert">
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
I resolved it by changing my logic, because you can't nest if statements in Liquid.
I'm looking to display information from a csv file on a jekyll-generated site. I need to search for the appropriate category in the csv file, then display four of them on the page. Filtering to the selected category is no problem, but I'm having difficulty limiting the output to four.
Is there a way to apply a limit to an if statement? Or is there any other way to write this? I'm not that savvy in Liquid, so it's extremely likely that I'm missing an obvious solution.
Basic code to make all the applicable data show up on the screen:
{% for study in site.data.studies %}
{% if study.category contains "foo" %}
<div class="col-sm-3">
<h3>{{ study.title }}</h3>
<div class="list-of-attributes">
<h6>Attributes: </h6>
{{ study.attributes }}
</div>
</div>
{% else %}
{% continue %}
{% endif %}
{% endfor %}
I've also tried unless and tablerow, neither of which worked at all. Am I at least on the right track? How can I limit this forloop to stop at four items?
Thank you!
Ideally data should be filtered before rendering however you can also create a variable in liquid to hold the number of stuff rendered
{% assign rendered = 0 %}
{% for study in site.data.studies %}
{% if study.category contains "foo" %}
<div class="col-sm-3">
<h3>{{ study.title }}</h3>
<div class="list-of-attributes">
<h6>attributes: </h6>
{{ study.attributes }}
</div>
</div>
{% assign rendered = rendered | plus: 1 %}
{% if rendered == 4 %}
{% break %}
{% endif %}
{% endif %}
{% endfor %}
The ideal solution as I said would be to create your own filter which does all the work (filter by category and limit the number of results)
{% assign filtered = site.data.studies | my_custom_filter %}
{% for study in filtered %}
<div class="col-sm-3">
<h3>{{ study.title }}</h3>
<div class="list-of-attributes">
<h6>attributes: </h6>
{{ study.attributes }}
</div>
</div>
{% endfor %}
Presuming that your category is a string, not an array, you can do :
{% assign selected = site.data.studies | where: 'category','foo' %}
{% for study in selected limit:4 %}
<div class="col-sm-3">
<h3>{{ study.title }}</h3>
<div class="list-of-attributes">
<h6>Attributes: </h6>
{{ study.attributes }}
</div>
</div>
{% endfor %}
And if your category is a string like "foo, bar, baz" or and array of strings you can use the jekyll 3.2 where_exp filter like this :
{% assign selected = site.data.studies | where_exp:"item", "item.category contains 'foo'" %}