Hey guys I am really new to shopify. and trying to learn liquid. I am getting an invalid JSON tag in schema/ and I am not quite sure where it is. I am just trying to have 4 basic blocks that you can add to a section with a image and a title underneath. I don't have the content block made right now because I can't get the image one to work in the first place.
{% for block in section.blocks %}
<div class="grid-item" {{ block.shopify_attributes }}>
{% case block.type %}
{% when 'image' %}
<img src="{{ block.settings.image | img_url }}">
</div>
{% when 'text' %}
{{ block.settings.content }}
{% endcase %}
{% endfor %}
{% schema %}
{
{
"blocks": [
{
"name": "Service",
"limit": 4
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "image"
}
]
}
]
}
}
{% endschema %}
Once again, Like I said, I am really new to all of this so any point in the right direction or help would be crazy awesome! Thanks!
missing a comma after your limit: 4?
Related
I am trying to access and loop through the collection list inside the blocks:
The following code should loop through this collection list
<!-- If The Category Has So Many Subs -->
<div class="sub-cat-childs-container">
{% for block in section.blocks %}
{% case block.type %}
{% when 'Sub-Category' %}
{% if shop.locale == 'en' %}<style>.subCategory::after{float: right}</style>{% endif %}
<div class="sub--category--contnet" id="sub-category-{{ block.settings.sub_category_collection.id }}">
<div class="sub-sub---items-row">
Loop Throug The CollectionList {{ block.settings.sub-subcategory-collection_list }}
</div>
</div>
{% endcase %}
{% endfor %}
</div>
{% endif %}
The following is the schema I am trying to get the collection list from it:
{% schema %}
{
"name" : "Main Category",
"settings" :
[
],
"blocks" :
[
{
"name" : "Sub-Category",
"type" : "Sub-Category",
"settings" :
[
{
"type": "collection_list",
"id": "sub-subcategory-collection_list",
"label": "Sub Sub-Categories"
}
]
}
],
"presets" :
[
{
"name" : "Main Category"
}
]
}
{% endschema %}
Any one can help me to display all the collection in this collecion List
id:sub-subcategory-collection_list.
Thank you all...
You can create a new for loop to loop over the collections you have selected, for example:
{% for collection in block.settings.sub-subcategory-collection_list %}
{{ collection.title }}
{% endfor %}
The collection_list type gives you an array of Collection objects which you can loop over, as documented here
As a side note, you should aim to keep all your setting IDs as snake-case, to match Shopify's practice guides
Here is the code that I am using in ansible.
I am at beginner level so please forgive me if my question is naive
{% for item in results.response %}
{% for value in item.values() %}{{ value }}{% if not loop.last %},{% endif %}{% endfor %}
{{'\n'}}
{% if not loop.last %},{% endif %}
{% endfor %}
Here is the data format and the output (no match data to format , I just grabbed two random sections of the stdout and the output file
Data
results.response [
{
"address": "10.224.1.61",
"age": "32",
"interface": "GigabitEthernet9/7",
"mac": "cc16.7eec.1100",
"type": "ARPA"
},
{
"address": "10.70.0.150",
"age": "-",
"interface": "GigabitEthernet9/4",
"mac": "001d.7151.a400",
"type": "ARPA"
},
{
"address": "10.224.33.51",
"age": "-",
"interface": "TenGigabitEthernet2/2",
"mac": "001d.7151.a400",
"type": "ARPA"
},
{
"address": "10.224.32.51",
"age": "-",
"interface": "TenGigabitEthernet2/3",
"mac": "001d.7151.a400",
"type": "ARPA"
}
]
Output
,device1,FastEthernet6/0/0,-,ARPA,001d.7151.a400,171.255.50.133
,device1,FastEthernet6/0/0,132,ARPA,84b2.61a7.3a20,141.255.50.134
,device1,FastEthernet6/0/1,-,ARPA,001d.7151.a400,131.1.9.233
,device1,FastEthernet6/0/1,32,ARPA,0013.c446.2d91,101.1.9.234
,device1,GigabitEthernet5/1,-,ARPA,001d.7151.a400,110.1.15.174
,device1,GigabitEthernet5/1,140,ARPA,c471.feeb.a080,110.1.52.173
,device1,Vlan112,-,ARPA,001d.7151.a400,120.224.40.114
c.f. the Jinja2 docs here
You can also strip whitespace in templates by hand. If you add a minus sign (-) to the start or end of a block (e.g. a For tag), a comment, or a variable expression, the whitespaces before or after that block will be removed:
{% for item in seq -%}
{{ item }}
{%- endfor %}
Your code has both implied and explicit newlines.
{% for value in item.values() %}{{ value }}{% if not loop.last %},{% endif %}{% endfor %}
{{'\n'}}
Take that {{'\n'}} line out and try it. You could also organize it visually with manual space management. Watch the dashes by the percent signs -
{% for item in results.response -%}
{%- for value in item.values() -%}
{# keep none of the spacing aaround this value #}
{{ value }}{%- if not loop.last %},{% endif -%}
{# keep none of the spacing at the end the if #}
{%- endfor %}
{# KEEP the spacing at the end of each inner iteration #}
{% endfor %}
Will try to test this when I can get to a server.
Give me a bit.
These are my JSON data:
[
{
"name":"unit 1",
"lessons":{
"1":{
"name":"lesson 1",
"content":"......."
},
"2":{
"name" "lesson 2",
"content":"......."
}
}
]
I can access these data using the following Twig code:
{% for unit in units %}
{{ unit.name }}
{% for lesson in unit.lessons %}
{{ lesson.name }}
{% endfor %}
{% endfor %}
But I want to access the lesson number, to make a hyperlink to the content. How can I do that?
You can Iterating over Keys and values as example:
{% for key, lesson in unit.lessons %}
{{ key}}
{{ lesson.name }}
{% endfor %}
Hope this help
Actually, I don't know how to access jsonfield data in the template. I tried something like this
{% for key in place.places_to_visit %}
{{ key }}:{{ value }}
{% endfor %}
But it is showing all json data that I have added including {} and " " and also same for Arrayfield of characters
I also want to add an image in that jsonfield, how to do that? Does that image need to be media directory and then I should include its path? Or some other ways to do that?
It is also showing error as follows
"[05/Sep/2017 23:03:00] "GET /ontheway/1/ HTTP/1.1" 200 4238"
jsonfield data of places_to visit is
"Places to visit": [
{
"name" : "some name",
"overview" : " some data",
"iamge": "image path"
}
{
"name" : "some name",
"Overview": " some data",
"image": "image path"
}
]
Thank you in advance
you can try to use items:
{% for data in place.places_to_visit %}
{% for key, value in data.items %}
{% if key == 'image' %}
<img src="{{ value }}">
{% else %}
<div> {{ key }}:{{ value }} </div>
{% endif %}
{% endfor %}
{% endfor %}
I have a JSON file with the following structure:
{
"resources": [
{
"date": "Nov 7",
"content": [
{
"articleTitle":"The Distribution of Users’ Computer Skills: Worse Than You Think",
"articleUrl":"https://www.nngroup.com/articles/computer-skill-levels/?ref=boomkrak",
"articleAuthor": "Jakob Nielson",
"articleTag": "ux, web design"
},
{
"articleTitle":"How to Use Animation to Improve UX",
"articleUrl":"https://uxplanet.org/how-to-use-animation-to-improve-ux-338819e93bdb#.84b3m022s?ref=boomkrak",
"articleAuthor": "Nick Babich",
"articleTag": "ux, animation"
}
]
},
{
"date": "Nov 15",
"content": [
{
"articleTitle":" 7 Things Every Designer Needs to Know about Accessibility",
"articleUrl":"https://medium.com/salesforce-ux/7-things-every-designer-needs-to-know-about-accessibility-64f105f0881b#.5pgg5014x?ref=boomkrak",
"articleAuthor": "Jesse Hausler",
"articleTag": "ux, web design, accessibility"
},
{
"articleTitle":"Get the most out of your research with storytelling",
"articleUrl":"https://blog.intercom.com/get-the-most-out-of-your-research-storytelling/?ref=boomkrak",
"articleAuthor": "Jillian Wells",
"articleTag": "design research, collaboration"
}
]
}
]
}
I want to show the article based on each tag. For example, if I want to show ux articles, then all articles with ux tag should be displayed.
Anyone know how to do it in Jekyll?
Considering that your datas are in _datas/articles.json, you can use this include file (_includes/listbyTag.html) :
{% assign tag = include.tag %}
{% assign days = site.data.articles.resources %}
{% assign list = ""| split: "/" %} {% comment %} creates an empty array {% endcomment %}
{% for day in days %}
{% for article in day.content %}
{% if article.articleTag contains tag %}
{% assign list = list | push: article %}
{% endif %}
{% endfor %}
{% endfor %}
{% if list.size != 0 %}
<h3>Found {{ list.size }} posts for tag : {{ tag }}</h3>
<ul>
{% for post in list %}
<li>{{ post.articleTitle }}</li>
{% endfor %}
</ul>
{% endif %}
Now you can include it anywhere with :
{% include listByTag.html tag="ux" %}
Or for a tag page :
---
tag: ux
title: my title
layout: default
---
{% include listByTag.html tag=page.tag %}