I'm trying to add images of products that a customer has bought to the Order Confirmed email notification. I currently am using this as my attempt:
<img src="{{ line.line_item | img_url: 'small' }}">
I tried that based on this page. I also tried the following:
{{ item.product.featured_image | product_img_url | img_tag }}
Neither way worked. All I'm getting back is a placeholder image that says "no image" on it. This leads me to believe that my syntax is correct, but Shopify can't find the image I'm looking for. I set an image for the product in the admin page, and to make sure I have a big image and a smaller one, as well as set an image on the variant (although there is only the default, one variant for this product). None of it is working. Does anyone have any experience in this and can point me in the right direction?
Thanks!
Thanks to the help of a coworker, we got this figured out. When looping through the line_items, do the following to get the image: <img src="{{ line.product.featured_image | product_img_url: 'thumb' }}"> and the image will output. There are a lot of different image sizes you can use in place of 'thumb'. Check those out here.
Hope this helps someone else!
The default Order Confirmation email template uses the img_url filter:
{% for line in line_items %}
<li>
<img src="{{ line | img_url: 'small' }}" />
{{ line.quantity }}x {{ line.title }} for {{ line.price | money }} each
</li>
{% endfor %}
This is preferable to using line.product.featured_image because it will display the line item's variant image if one exists.
From the Shopify docs for img_url:
For line_item, the URL of the line item's variant image is returned. If the variant does not have an assigned image, the URL of the product's featured image is returned.
Alternatively, you could replace <img src="{{ line | img_url: 'small' }}" /> with any of these options that use the img_tag filter:
{{ line | img_url: 'small' | img_tag }} // my preferred option
{{ line | img_tag }} // default size is 'small'
{{ line | img_tag: 'alt text', 'class1', 'thumb' }} // thumbnail image with alt text and CSS class
Related
I have similar issue that Wysiwyg images not moved to public cache
when I add a file or image in wysiwyg, it displays properly in editor but after saving, it doesn't display in admin nor front.
Generated markup src is incorrect/not properly replaced:
<picture id="irozi"><source srcset="{{ wysiwyg_image('22','d9ffaffc-f286-4707-bd4b-29504628acc2','wysiwyg_original','webp') }}" type="image/webp"><img src="{{ wysiwyg_image('22','0872c470-f50a-4290-8043-96ffd5e205d2','wysiwyg_original','') }}" id="icysf" alt="test picture"></picture>
my-file.csv
My field already exists (in a custom bundle) and "File applications" doesn't show in "Entity Management".
Do I need that conf? How to achieve it with a migration?
What else should I do to have a correct src for files and images?
File applications config is required if you want to display an image that is ACL protected within the application. You can set it using a migration, e.g.:
$queries->addQuery(
new UpdateEntityConfigFieldValueQuery(
'Acme\Demobundle\Entity\FancyFile',
'image',
'attachment',
'file_applications',
['default', 'commerce']
)
);
The issue might also be related to image processing. Please, check the log file for errors.
UPDATE
Also, as a WYSIWYG field has some twig placeholders it has to be rendered with the applied postprocessing.
On the storefront it should be rendered with:
{% if entity.contentStyle|length -%}
{%- apply spaceless -%}
<style type="text/css">{{ entity.contentStyle|render_content }}</style>
{%- endapply -%}
{%- endif %}
{{ entity.content|render_content }}
There are also ready-to-use layout block types: wysiwyg_style and text_with_placeholders.
On the back-office there is a macro
{% import '#OroEntityConfig/macros.html.twig' as entityConfig %}
{{ entityConfig.renderWysiwygContentPreview(entity.content)|raw }}
Where the entity.content is the field path to render.
The team will update the documentation to mention that.
Problem
Recently I added tag support for my personal blog, but I am not happy with a way that it was done.
Blog uses jekyll with github-pages, so my solution has many limitations that platform comes with.
In order to create tag javascript I created file tag/javascript/index.html with following content:
---
layout: tag
tag: javascript
---
And it in my tag layout file I have following code:
---
layout: default
---
<div class="tag-header">
posts related to <strong>{{ page.tag }}</strong>
</div>
{% for post in site.posts %}
{% if post.tags contains page.tag %}
<section class="post">
<header>
{{ post.title }}
</header>
<time>
{{ post.date | date_to_string }}
</time>
<summary>
{% if post.excerpt %}
{{ post.excerpt }}
read more
{% endif %}
</summary>
<div class="tags">
{% for tag in post.tags %}
<span>
#{{ tag }}
</span>
{% endfor %}
</div>
</section>
{% endif %}
{% endfor %}
Result is something like this posts related to javascript.
Question
How can I automate tag creation process, so it does not require manual tag file creation (tag/javascript/index.html from sample)?
Notice
I have read An easy way to support tags in a jekyll blog already, and the only working solution for github-pages was this one, which I don't like, because it puts all tags in one page.
Additionally note that I am using github-pages, so custom plugin is not an option.
You can find full sources here.
Current Jekyll (3.1.x) cannot generate tag page automatically. You need to use a custom plugin. But you don't want to.
Why ? It's not so difficult to change deployment process on github pages.
You can store you code in master and you generated page in gh-pages. This answer will give your more information on how to do it.
I try to display my custom data-prototype for a CollectionType. I followed this answer.
This is what I have:
{{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }}
<div class="form-group">
{{ form_label(form.answers, "Answers", {'label_attr': {'class': 'col-sm-2 control-label'}}) }}
{{ form_errors(form.answers) }}
<div id="mybundle_add_answers"
data-prototype="
{% filter escape %}
{% include 'MyBundle:Form:prototype_answers.html.twig' with {'form': form.answers.vars.prototype} %}
{% endfilter %}">
</div>
Add
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
This is working but, because of form_rest, it displays my data-prototype (mybundle_add_answers) a second time at the end of the form.
It seems that nobody have this problem so What did I do wrong here / forget? I use Symfony 3.0 maybe this is related?
I didn't find a way to do what I wanted with custom data-prototype. I don't know if this is because of Symfony 3 that I have a double widget.
Anyway I did what I wanted with custom collection_widget. If anyone is interested in : https://gist.github.com/cowlby/1294186
And if someone find an answer for this "double" widget problem, I'm still curious to know.
I've had the exact same problem.
After spending a day searching the web for this problem, I ended up simply not using {{ form_rest(form) }} and {{ form_end(form) }}. In my template I added the csrf token manually by using {{ form_widget(form._token) }}, then closed the </form> manually, because in my case that's all form_rest and form_end did.
I want another item above Total that displays the total quantity.
Any ideas on how to do this with Liquid and have it work within the Shopify Email Template?
Here's my current snippet:
<ul style="list-style-type:none;"> {% for line in line_items %} <li> {{ line.quantity }}x
{{ line.title }} for {{ line.price | money }} each </li> {% endfor %}
<li><br><b>Total: </b>{{ total_price | money }}</li>
</ul>
Any help with this would be most appreciated.
Thanks, Ben
I think you want {{ item_count }}. See the Shopify docs here for a list of the order variables you have access to in email templates:
item_count: A sum of all the items' quantities.
I'm new to jekyll and am working on building my site.
I have a "posts" layout where I'd like to have all the tags associated with the post appear in the left column. The problem I'm running into is that using {{ page.tags }} returns a list of tags that are not comma-separated and looks messy. See here for an example.
The html code for the layout page is:
<div class="span3">
</br>
<img src="{{ page.root }}assets/img/glyphicons_045_calendar.png" /> {{ page.date | > date: "%d %B %Y" }}
</br>
<img src="{{ page.root }}assets/img/glyphicons_066_tags.png" /> {{ page.tags }}
</div>
<div class="span9">
<h1> {{ page.title }} </h1>
{{ content }}
</div>
Any advice on how to (a) get the tags list to be comma-separated and (b) wrap around so it stays within the left column? Thanks!
You might try to put them inside a <p> tag so they can wrap around.
To have them comma-separated, you can follow the jekyll docs and use:
{{ page.tags | array_to_sentence_string }} => foo, bar, and baz
As is said in the Jekyll wiki.
For more precise control over what you can do with tags use the for operator:
<ul>
{% for tag in page.tags %}
<li> {{tag}} </li>
{% endfor %}
</ul>
This example is taken verbatim from somewhere. There are also more control structures to choose from.