Unescaping string? in Shopify - schema

I have 8 feature products added in my settings_schema.json . I want to output them by for loop by adding number on the end of settings.feature_product[incrementing integer]
This is my settings schema
{
"type": "product",
"id": "feature_product1",
"label": "Feature Product 1"
},
{
"type": "product",
"id": "feature_product2",
"label": "Feature Product 2"
},
{
"type": "product",
"id": "feature_product3",
"label": "Feature Product 3"
},
{
"type": "product",
"id": "feature_product4",
"label": "Feature Product 4"
},
{
"type": "product",
"id": "feature_product5",
"label": "Feature Product 5"
},
{
"type": "product",
"id": "feature_product6",
"label": "Feature Product 6"
},
{
"type": "product",
"id": "feature_product7",
"label": "Feature Product 7"
},
{
"type": "product",
"id": "feature_product8",
"label": "Feature Product 8"
}
This is the code in my snippet
{% for i in (1..8) %}
{% if i <= 8 %}
<div class="case_item">
{% assign case_var = 'settings.feature_product' | append: i | strip_html %}
{{ all_products[case_var].title }}
</div>
{% endif %}
{% endfor %}
But it doesn't work :( I tried to print the case_var and the result is..
settings.feature_product1
settings.feature_product2
.
.
settings.feature_product3
Anyone could help me?

{% for i in (1..8) %}
{% capture productid %}feature_product{{ i }}{% endcapture %}
{% if settings[productid] != '' %}
<div class="case_item">
{% assign productslug = settings[productid] %}
<h3>{{ all_products[productslug].title }}</h3>
<em>{{ all_products[productslug].price | money }}</em>
</div>
{% endif %}
{% endfor %}

Related

How To Display Featured Posts From Multiple Blogs in Shopify?

I have multiple blogs on my Shopify site. I'm trying to display posts from ALL blogs on the site in the featured section on the homepage. However, when I attempt to select them in the admin area, it only allows me to select one at a time.
What do I need to put in the {% schema %} (or template code) to allow me to select more than one blog in the theme's admin area, thus displaying posts from more than one blog in featured section in the template?
Here is my current {% schema %}:
{% schema %}
{
"name": "Blog posts",
"class": "index-section",
"settings": [
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Blog posts"
},
{
"id": "blog",
"type": "blog",
"label": "Blog"
},
{
"type": "range",
"id": "post_limit",
"label": "Posts",
"min": 3,
"max": 12,
"step": 3,
"default": 3
},
{
"type": "checkbox",
"id": "blog_show_author",
"label": "Show author",
"default": false
},
{
"type": "checkbox",
"id": "blog_show_date",
"label": "Show date",
"default": true
},
{
"type": "checkbox",
"id": "show_view_all",
"label": "Show 'View all' button",
"default": false
}
],
"presets": [
{
"name": "Blog posts",
"category": "Blog",
"settings": {
"blog": "News",
"post_limit": 3
}
}
]
}
{% endschema %}
Have you tried the simplest of Liquid constructions like:
{% for blog in blogs %}
<p>I am blog {{ blog.title }}</p>
{% endfor %}
That kind of thing? If you have many blogs, I would start with that. If you cannot iterate your existing blogs, you have no hope of showing off their contents in a section of your store, whatever that may be.
Could you try this? Just add some more block schema
<div class = "blog-container">
{% if section.settings.blog != blank %}
{% for blog in section.settings.blog %}
<p>{{blog.title}}</p>
{% endfor %}
{% endif %}
{% if section.settings.blogone != blank %}
{% for blog in section.settings.blogone %}
<p>{{blog.title}}</p>
{% endfor %}
{% endif %}
{% if section.settings.blogtwo != blank %}
{% for blog in section.settings.blogtwo %}
<p>{{blog.title}}</p>
{% endfor %}
{% endif % }
</div>
{% schema %}
{
"name": "Blog posts",
"class": "index-section",
"settings": [
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Blog posts"
},
{
"id": "blog",
"type": "blog",
"label": "Blog"
},
{
"id": "blogtwo",
"type": "blog",
"label": "Blog Two"
},
{
"id": "blogthree",
"type": "blog",
"label": "Blog Three"
},
{
"type": "range",
"id": "post_limit",
"label": "Posts",
"min": 3,
"max": 12,
"step": 3,
"default": 3
},
{
"type": "checkbox",
"id": "blog_show_author",
"label": "Show author",
"default": false
},
{
"type": "checkbox",
"id": "blog_show_date",
"label": "Show date",
"default": true
},
{
"type": "checkbox",
"id": "show_view_all",
"label": "Show 'View all' button",
"default": false
}
],
"presets": [
{
"name": "Blog posts",
"category": "Blog",
"settings": {
"blog": "News",
"post_limit": 3
}
}
]
}
{% endschema %}

Can we create something similar to {{ content_for_index }} as per our requirement and use it in the pages we want? SHOPIFY Theme

In the shopify theme that I am editing I want to create a page where there are so many sections. I am searching for a way to allow admin user to change the order of all the sections from the customiser.
Found a work around for changing the order of all the sections.
[credit]
this solution is based on one post from shopify community: https://community.shopify.com/c/Shopify-Design/Nested-Sections/td-p/424873
I have created five files where you can see my workaround
[Files]
templates/page.sequence.liquid
sections/a.liquid
sections/b.liquid
sections/c.liquid
sections/seq.liquid
templates/page.sequence.liquid
{%capture one%}{% section 'a' %}{%endcapture%}
{%capture two%}{% section 'b' %}{%endcapture%}
{%capture three%}{% section 'c' %}{%endcapture%}
{% capture collection_template_content %}
{% section 'seq' %}
{% endcapture %}
{% assign one = one | replace: 'class="shopify-section"', 'class="shopify-section-nested"' %}
{% assign two = two | replace: 'class="shopify-section"', 'class="shopify-section-nested"' %}
{% assign three = three | replace: 'class="shopify-section"', 'class="shopify-section-nested"' %}
{% assign collection_template_content = collection_template_content | replace: "%%a%%", one %}
{% assign collection_template_content = collection_template_content | replace: "%%b%%", two %}
{% assign collection_template_content = collection_template_content | replace: "%%c%%", three %}
{{collection_template_content}}
sections/a.liquid (and two more similar files: b.liquid and c.liquid)
<div >
Section A
</div>
{% schema %}
{
"name": "Section A",
"settings": [
]
}
{% endschema %}
{% stylesheet %}
{% endstylesheet %}
{% javascript %}
{% endjavascript %}
sections/seq.liquid
<div class="page-width">
{% if section.settings.id_a == "1"%}%%a%%{% endif %}
{% if section.settings.id_b == "1"%}%%b%%{% endif %}
{% if section.settings.id_c == "1"%}%%c%%{% endif %}
{% if section.settings.id_a == "2"%}%%a%%{% endif %}
{% if section.settings.id_b == "2"%}%%b%%{% endif %}
{% if section.settings.id_c == "2"%}%%c%%{% endif %}
{% if section.settings.id_a == "3"%}%%a%%{% endif %}
{% if section.settings.id_b == "3"%}%%b%%{% endif %}
{% if section.settings.id_c == "3"%}%%c%%{% endif %}
</div>
{% schema %}
{
"name": "Section Main",
"settings": [
{
"type": "select",
"id": "id_a",
"label": "Order A",
"options": [
{
"group": "value",
"value": "1",
"label": "1"
},
{
"group": "value",
"value": "2",
"label": "2"
},
{
"group": "value",
"value": "3",
"label": "3"
}
],
"default": "1",
"info": "text"
},
{
"type": "select",
"id": "id_b",
"label": "Order B",
"options": [
{
"group": "value",
"value": "1",
"label": "1"
},
{
"group": "value",
"value": "2",
"label": "2"
},
{
"group": "value",
"value": "3",
"label": "3"
}
],
"default": "1",
"info": "text"
},
{
"type": "select",
"id": "id_c",
"label": "Order C",
"options": [
{
"group": "value",
"value": "1",
"label": "1"
},
{
"group": "value",
"value": "2",
"label": "2"
},
{
"group": "value",
"value": "3",
"label": "3"
}
],
"default": "1",
"info": "text"
}
]
}
{% endschema %}
{% stylesheet %}
{% endstylesheet %}
{% javascript %}
{% endjavascript %}
One problem with this is, the theme customiser is not happy if we use such workaround, I have an error as shown in the snapshot, other then that, the content works just fine when we visit the page.open image

Having a issue with shopify resizing image from liquid file

Hello I'm trying to edit an image make it smaller or custom size but not familiar with liquid. Thank you for the help guys. I added some code. I think its default as certain percentage but not sure. Let me know if you guys need some extra code or information from me.
// settings_data.json file
"index-newsletter": {
"type": "index-newsletter",
"settings": {
"title": "Newsletter",
"richtext": "<p>Subscribe to get special offers, free giveaways, and once-in-a-lifetime deals.<\/p>",
"width": "full",
"flex_align": "align--middle-left",
"text_color": "dark",
"height": "screen-height-one-third",
"bg_image": "shopify:\/\/shop_images\/Grazioso_Logo321321_db2a67b3-d13f-4d64-a73d-c82f176fd6a5.png",
"overlay_opacity": 50,
"overlay_color": "#ffffff"
}
},
<!-- /sections/newsletter.liquid -->
{%- assign img_url = section.settings.bg_image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
<style>
{%- if section.settings.text_color == 'white' -%}
.index-newsletter-{{ section.id }},
.index-newsletter-{{ section.id }} .input-group.newsletter-form input { color: #fff; }
{%- endif -%}
</style>
<div class="index-newsletter index-newsletter-{{ section.id }}" data-section-id="{{ section.id }}" data-section-type="newsletter">
<div class="wide-image js-overflow-container {{ section.settings.height }}"
data-aos-duration="500"
data-aos="fade-up">
<div class="hero__content__wrapper hero__content--transparent {{ section.settings.flex_align }}">
<div class="hero__content hero__content--{{ section.settings.width }} js-overflow-content">
<div class="newsletter__content">
{% if section.settings.title != '' %}
<h5 class="newsletter__title">{{ section.settings.title }}</h5>
{% endif %}
{% if collection.description != '' %}
<div class="rte">
{{ section.settings.richtext }}
</div>
{% endif %}
<div class="newsletter-signup">
{% include 'newsletter-form' %}
</div>
</div>
</div>
</div>
{% if section.settings.bg_image %}
{% if section.settings.height == 'image-height' %}
<img class="lazyload responsive-wide-image"
alt="{{ section.settings.bg_image.alt | default: section.settings.title }}"
src="{{ section.settings.bg_image | img_url: '18x' }}"
data-src="{{ img_url }}"
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048, 2450, 2700, 3000, 3350, 3750, 4100]"
data-aspectratio="{{ section.settings.bg_image.aspect_ratio }}"
data-parent-fit="cover"
data-sizes="auto"/>
{% else %}
<div class="background-size-cover lazyload" data-bgset="{% include 'bgset', image: section.settings.bg_image %}"></div>
{% endif %}
<noscript>
<img src="{{ section.settings.bg_image | img_url: '1440x' }}" alt="{{ section.settings.bg_image.alt | default: collection.title }}" class="responsive-wide-image"/>
</noscript>
{% assign overlay_opacity = section.settings.overlay_opacity | times: 0.01 %}
<div class="image-overlay" style="background-color:{{ section.settings.overlay_color }} !important; opacity:{{ overlay_opacity }};"></div>
{% endif %}
</div>
</div>
{% schema %}
{
"name": "Newsletter",
"settings": [
{
"type": "header",
"content": "Content"
},
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Newsletter"
},
{
"id": "richtext",
"type": "richtext",
"label": "Subheading",
"default": "<p>Subscribe to get special offers, free giveaways, and once-in-a-lifetime deals.</p>"
},
{
"type": "paragraph",
"content": "Subscribers are under 'Accepts Marketing' in your [customer admin](/admin/customers)."
},
{
"type": "select",
"id": "width",
"label": "Width",
"default": "full",
"options": [
{ "value": "full", "label": "Full" },
{ "value": "default", "label": "Default" }
]
},
{
"type": "select",
"id": "flex_align",
"label": "Text alignment",
"default": "align--middle-left",
"options": [
{ "value": "align--middle-left", "label": "Left" },
{ "value": "align--middle-center", "label": "Center" },
{ "value": "align--middle-right", "label": "Right" }
]
},
{
"type": "select",
"id": "text_color",
"label": "Text color",
"default": "dark",
"options": [
{ "value": "dark", "label": "Dark" },
{ "value": "white", "label": "White" }
]
},
{
"type": "select",
"id": "height",
"label": "Section height",
"default": "screen-height-one-third",
"options": [
{ "value": "screen-height-one-half", "label": "1/2 of screen"},
{ "value": "screen-height-one-third", "label": "1/3 of screen"},
{ "value": "five-fifty-height-hero ", "label": "550px" },
{ "value": "four-fifty-height-hero", "label": "450px" },
{ "value": "three-fifty-height-hero", "label": "350px" },
{ "value": "two-fifty-height-hero", "label": "250px" },
{ "value": "image-height", "label": "Image height" }
]
},
{
"type": "header",
"content": "Background"
},
{
"type": "image_picker",
"id": "bg_image",
"label": "Background image"
},
{
"type": "range",
"id": "overlay_opacity",
"label": "Opacity",
"info": "Increase contrast for legible text.",
"unit": "%",
"min": 0,
"max": 90,
"step": 5,
"default": 0
},
{
"type": "color",
"id": "overlay_color",
"label": "Overlay color",
"default": "#fff"
}
],
"presets": [
{
"category": "Promotional",
"name": "Newsletter"
}
]
}
{% endschema %}
{% if section.settings.bg_image %}
{% if section.settings.height == 'image-height' %}
<img class="lazyload responsive-wide-image"
alt="{{ section.settings.bg_image.alt | default: section.settings.title }}"
src="{{ section.settings.bg_image | img_url: '18x' }}"
data-src="{{ img_url }}"
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048, 2450, 2700, 3000, 3350, 3750, 4100]"
data-aspectratio="{{ section.settings.bg_image.aspect_ratio }}"
data-parent-fit="cover"
data-sizes="auto"/>
{% else %}
<div class="background-size-cover lazyload" data-bgset="{% include 'bgset', image: section.settings.bg_image %}"></div>
{% endif %}
{
"type": "select",
"id": "height",
"label": "Section height",
"default": "screen-height-one-third",
"options": [
{ "value": "screen-height-one-half", "label": "1/2 of screen"},
{ "value": "screen-height-one-third", "label": "1/3 of screen"},
{ "value": "five-fifty-height-hero ", "label": "550px" },
{ "value": "four-fifty-height-hero", "label": "450px" },
{ "value": "three-fifty-height-hero", "label": "350px" },
{ "value": "two-fifty-height-hero", "label": "250px" },
{ "value": "image-height", "label": "Image height" }
]
},
in the theme editing, if you choose the height setting to image height. These will happen
because you are using lazyload, there will be a small picture of 18px used, hence this line src="{{ section.settings.bg_image | img_url: '18x' }}"
the picture will automatically resize base on the screen width;
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048, 2450, 2700, 3000, 3350, 3750, 4100]"
if you want to have the image at max-width 2048, just remove the the number from data-width; I.e. I only want image size 180 - 2048. I will remove 2450, 2700, 3000, ...
another solution is to add max-width to the image;i.e add style="max-width: 500px" to the img tag
{% if section.settings.bg_image %}
{% if section.settings.height == 'image-height' %}
<img class="lazyload responsive-wide-image"
alt="{{ section.settings.bg_image.alt | default: section.settings.title }}"
src="{{ section.settings.bg_image | img_url: '18x' }}"
data-src="{{ img_url }}"
data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048, 2450, 2700, 3000, 3350, 3750, 4100]"
data-aspectratio="{{ section.settings.bg_image.aspect_ratio }}"
data-parent-fit="cover"
data-sizes="auto"/
style="max-width: 500px;">
{% else %}
<div class="background-size-cover lazyload" data-bgset="{% include 'bgset', image: section.settings.bg_image %}"></div>
{% endif %}

Is there a way to have multiple Block types in a Shopify section?

In a Shopify section I have an image picker block to make a gallery, and in the same section I have a url block to make any number of buttons.
The problem is both block types appear in the same 'Content' area of the theme editor. This makes it look quite confusing for an editor.
Is there a way to have 2 separate blocks areas, one for the image gallery and the other for buttons?
"blocks": [
{
"type": "button",
"name": "Button",
"settings": [
{
"type": "url",
"id": "button_link",
"label": "Button link"
}
]
},
{
"type": "image",
"name": "Image slide",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
}
]
}
]
No, at current there is no way to tell Shopify to display blocks in this way. All blocks can be arranged to be in any order, regardless of what the 'type' of each block is. Whoever is administering the store would need to manually arrange the blocks into a sensible order.
If you want to make it easier to split up your block types during the rendering of the items, you can use something like this:
{% assign image_blocks = section.blocks | where: 'type', 'image' %}
{% for block in image_blocks %}
<!-- Stuff -->
{% endfor %}
{% assign button_blocks = section.blocks | where: 'type', 'button' %}
{% for block in button_blocks %}
<!-- Stuff -->
{% endfor %}
Create 2 different sections and include both .e.g:
{% section 'buttons' %}
{% section 'images' %}
Where:
sections/buttons.liquid
{% schema %}
{
"name": "Buttons",
"class": "buttons-section",
"blocks": [
{
"type": "button",
"name": "Button",
"settings": [
{
"type": "URL",
"id": "button_link",
"label": "Button link"
}
]
}
]
}
{% endschema %}
sections/images.liquid
{% schema %}
{
"name": "Images",
"class": "images-section",
"blocks": [
{
"type": "image",
"name": "Image slide",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
}
]
}
]
}
{% endschema %}
So you'll get this:

Shopify Product Data

I'm trying to add the product url and image to a div within a slider. However, I added the product dropdown to the schema, but it isn't pulling the data to the div. Please find the schema below:
{% schema %}
{
"name": "Product-Slideshow",
"settings": [
{
"id": "text-box",
"type": "text",
"label": "Heading",
"default": "Title"
}
],
"blocks": [
{
"type": "select",
"name": "Add Product",
"settings": [
{
"type": "product",
"id": "id",
"url": "url",
"label": "text",
"info": "text"
},
]
}
],
"presets": [
{
"name": "Product-Slideshow",
"category": "Image",
"blocks": [
{
"type": "select"
},
{
"type": "select"
}
]
}
]
}
{% endschema %}
Here is the div it is to be placed in.
<div class="owl-carousel">
{% for block in section.blocks %}
<div><a href="{{ product.url }}" class="btn"><img src="{{ image.src |
product_img_url }}"></a></div>
{% endfor %}
</div>
Any help would be greatly appreciated.
You must call your block settings as explained here :
https://help.shopify.com/themes/liquid/objects/block#block-settings
For example, something like {{ block.settings.image }}