Add “blocks” in 'settings_schema.json' in shopify theme - themes

I am new to Shopify and building my custom theme in Shopify I want to add "blocks" in settings_schema.json as I add in the section schema, Is it possible? if yes then how can I add it? Please help me
I have added the following code:
[
{
"name": "theme_info",
"theme_name": "Slate",
"theme_version": "0.11.0",
"theme_author": "Shopify",
"theme_documentation_url": "https:\/\/shopify.github.io\/slate\/",
"theme_support_url": "https:\/\/github.com\/Shopify\/slate"
},
{
"name": "Colors",
"settings": [
{
"type": "header",
"content": "General colors"
},
{
"type": "color",
"id": "color_theme",
"label": "Theme color",
"default": "#efeeeb",
"info": "Used for theme"
},
{
"type": "color",
"id": "color_primary",
"label": "Primary color",
"default": "#4d4d4d",
"info": "Used for text links, and primary buttons"
}
],
"blocks": [
{
"type": "product_colors",
"name": "Product colors",
"settings": [
{
"type": "color",
"id": "color_label",
"label": "Color label",
"default": "red"
},
{
"type": "color",
"id": "color_code",
"label": "Color code",
"default": "#ff0000"
}
]
}
]
}
]
But it gives an error:
Error: Section 2: 'blocks' is not a valid attribute
Any other solutions also appreciated

Blocks are not supported in the settings_schema.json file.
Blocks are only supported inside section files inside a {% schema %}{% endschema %} tags.
There are a few workarounds to your problem.
Use linklists
If you must use the settings_schema.json than you can use a link_list field to select a specific link_list where you can createa a navigation with color label as link title and hex code as the link url address.
Use seprate section
Use a separate section for the colors where you will have the option for the blocks.
Use textarea
You can use a textarea and with a little splitting you can get the effect you want.
For example the value of the textarea will be:
Black|#000000
White|#ffffff
Grey|#cccccc
And you will do something like:
{% assign textarea = settings.textarea | newline_to_br | split: '<br /> %}
{% for text_row in textarea %}
{% assign text_row_array = text_row | split: '|" %}
{% assign color_name = text_row_array[0] %}
{% assign color_hex = text_row_array[1] %}
...
{% endfor %}
Sum up
The most user friendly option is the section option, but you can decide what suit your needs best.

Related

PUT inventory custom fragment

This is my device inventory with the custom tasks array:
{
...
"c8y_IsDevice": {},
"tasks": [
{
"task_status" : "NEW",
"task_id" : "1",
"task_data" : {
...
}
},
{
"task_status" : "DONE",
"task_id" : "2",
"task_data" : {
...
}
},
...
]
...
}
I want to create a MQTT/SMARTREST PUT template to update a task by id and status.
For example: 800,[task_id],[task_status]
I am not able to find a way for this, especially it's an json array and all my attempts end up in overwriting the complete json array.
Maybe there's sth. like a condition, if task_id = x -> set task_status = y
Thank you.
You can only replace the whole fragment. There is no way to partially modify fragments.
one way to do it is get the whole array, using it for create a new one locally with the changes to want to do and finally put it again into the database. It is not a kind of solution but have been working for me.
Thanks for the info, but I still got a question about updating an array.
Concerning your answers I want to update the whole fragment.
This is my inventory:
"tasks": [
{
"address": {
"street": "Street",
"street_number": "1"
},
"description": "Test Description",
"id": "1",
"status": "NEW"
},
{
"address": {
"street": "Street2",
"street_number": "2"
},
"description": "Test Description 2",
"id": "2",
"status": "DONE"
}
]
My template:
801,<$.tasks.status>,<$.tasks.description>,<$.tasks.address.street>,<$.tasks.address.street_number>
Template screenshot
Now I publish:
//801,SERIAL,status,description,street_name,street_nr
801,SERIAL,NEW,1,2,3,4
Of course, this will overwrite the array and just set a json object tasks.
"tasks": {
"address": {
"street": "2",
"street_number": "3"
},
"description": "1",
"status": "NEW"
}
So I tried tasks[*]/tasks[] in my template (like in response templates), but this won't work too. I don't get it, maybe you can give me a small solution about putting a complete fragment with an array inside.

Custom made sections not appearing with Shopify's new theme editor

With the release of the new theme editor I've been assigned to build a new client's website using Shopify's new theme builder framework.
Everything has been going fine except that when I go to create a new 'Section' in the backend it fails to appear within the Theme Editor's 'Sections' area.
Any idea what's going wrong here? Is there another JSON file that is associated with sections that I'm missing?
<div id="callToActions">
<div class="grid grid--no-gutters">
<div class=""></div>
</div>
</div>
{% schema %}
{
"name": "Call to Actions",
"class": "index-section index-section--flush",
"settings": [
{
"id": "cta_1_title",
"type": "text",
"label": "CTA 1 Title",
"default": "Dryups Specials"
}
]
}
{% endschema %}
You're almost there, just missing one thing. Sections will only show up as options to be added if they have a preset defined.
This update will make it show up:
{% schema %}
{
"name": "Call to Actions",
"class": "index-section index-section--flush",
"settings": [
{
"id": "cta_1_title",
"type": "text",
"label": "CTA 1 Title",
"default": "Dryups Specials"
}
],
"presets": [{
"name": "Call to Actions",
"category": "Text"
}]
}
{% endschema %}
Note the category. If omitted, it'll end up under Miscellaneous.

jsonpatch adding element to array and creating it if not exist

I'm trying to append an element to an array. But i cannot ensure that the array alread exists. So it should be created if not.
This example works:
Source json:
{
"data": []
}
Patch doc:
[{
"op":"add",
"path":"/data/-",
"value": "foo"
}]
But in this case it will not append anything:
Source json:
{}
I tried a solution by adding first an empty array and then appending, but this will always clear existing entries:
[{
"op":"add",
"path":"/scores",
"value": []
},
{
"op":"add",
"path":"/scores/-",
"value": {
"time":1512545873
}
}]
Have i missed something or is there no solution for this in the spec?
It's nice to you see you using fast-json-patch. I maintain this lib.
I would say you can't acheive this by pure JSON patches. You'll need some logic in your JS. Like the following:
var doc = {};
var patch = [{
"op": "add",
"path": "/scores/-",
"value": {
"time": 456
}
}];
var arr = jsonpatch.getValueByPointer(doc, '/scores');
if (!arr) {
jsonpatch.applyOperation(doc, {
"op": "add",
"path": "/scores",
"value": []
});
}
var out = jsonpatch.applyPatch(doc, patch).newDocument;
pre.innerHTML = JSON.stringify(out);
<script src="https://cdnjs.cloudflare.com/ajax/libs/fast-json-patch/2.0.6/fast-json-patch.min.js"></script>
<pre id="pre"></pre>

Mapfish Print Vector layer GeoJSON example?

I'm using MapFish Print to generate PDFs of maps, creating the map images in the pdf when I only use a WMS layer for base tiles is completely fine. Works as expected.
However, when I add a vector layer and a geoJSON object within it, mapfish print throws the following error:
Exception in thread "tilesReader3" java.lang.NullPointerException
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:113)
at org.mapfish.print.map.renderers.vector.PointRenderer.renderImpl(PointRenderer.java:49)
at org.mapfish.print.map.renderers.vector.GeometriesRenderer.render(GeometriesRenderer.java:69)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:62)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureRenderer.renderImpl(FeaturesRenderer.java:58)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:70)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer$FeatureCollectionRenderer.renderImpl(FeaturesRenderer.java:67)
at org.mapfish.print.map.renderers.vector.FeaturesRenderer.render(FeaturesRenderer.java:53)
at org.mapfish.print.map.readers.VectorMapReader$1.renderOnPdf(VectorMapReader.java:85)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:97)
at org.mapfish.print.map.ParallelMapTileLoader.handle(ParallelMapTileLoader.java:41)
at org.pvalsecc.concurrent.OrderedResultsExecutor.addOutput(OrderedResultsExecutor.java:148)
at org.pvalsecc.concurrent.OrderedResultsExecutor.access$600(OrderedResultsExecutor.java:23)
at org.pvalsecc.concurrent.OrderedResultsExecutor$Runner.run(OrderedResultsExecutor.java:181)
at java.lang.Thread.run(Unknown Source)
My query that I am sending to Mapfish print is a slightly modified version of the default sample (to use a different WMS as the default for the example is down), with the Vector layer added in, as follows:
{
layout: 'A4 portrait',
title: 'A simple example',
srs: 'EPSG:4326',
units: 'dd',
outputFilename: 'mapfish-print',
outputFormat: 'pdf',
layers: [
{
type: 'WMS',
format: 'image/png',
layers: ['OSM-GB:__all__'],
baseURL: 'http://www.osmgb.org.uk/ogc/wms'
},
{
type: 'Vector',
geoJson: {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0996621,
51.5059247
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.099332,
51.5072000
]
},
"properties": {
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.0945508,
51.50240484
]
},
"properties": {
}
}
]
}
}
],
pages: [
{
center: [0.09, 51.50],
scale: 4000000,
dpi: 190,
mapTitle: "First map",
comment: "The \"routes\" layer is not shown (the scale is too small)",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
},
{
center: [0.09, 51.50],
scale: 500000,
dpi: 190,
mapTitle: "Second map",
comment: "This is a zoomed in version of the first map. Since the scale is more appropriate, we show the \"routes\" layer.",
data: [
{id:1, name: 'blah', icon: 'icon_pan'},
{id:2, name: 'blip', icon: 'icon_zoomin'}
]
}
]
}
The GeoJSON validates and displays on geojsonlint.com, just fine. Having looked through the source for mapfish print I cannot figure out why exactly this is occurring. Though it seems to be something to do with styles, I have had no luck adding one into the request to fix this issue.
-- Update:
If anybody else ever comes across this issue, the problem was that (undocumented), you have to define within the vector layer, a set of styles, and make sure each feature in the geoJSON uses a style.
The problem was that (undocumented), you have to define within the vector layer, a set of styles and a styleproperty, and make sure each feature in the geoJSON uses a style.
The styles themselves are SVG styles, although many of the tags are renamed, so rather than being fill-color, they will be fillColor.
See here for a bit more detail: http://www.mapfish.org/doc/print/protocol.html#layers-params
The SVG styles which need to be defined are in the form of OpenLayers.Feature.Vector.style

Filter by languages in 2nd and 4th level keys of a couchdb document

Given the following document in CouchDB....
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [
{ "locale": "en", "value": "Example" },
{ "locale": "de", "value": "Beispiel" },
{ "locale": "fr", "value": "Exemple" }
],
"details": [
{ "locale": "en", "value": "An Example is here" },
{ "locale": "de", "value": "Ein Beispiel ist heir" }
{ "locale": "en", "value": "Un exemple est ici" }
]
}
...how can I write a view that will allow me to return a partial document with
the undesired languages filtered out?
curl ..snip.. '_design/locale_filter/?locale=en,de,fr,it'
curl ..snip.. '_design/locale_filter/?locale=en,fr'
curl ..snip.. '_design/locale_filter/?locale=en'
Should return something looking like this:
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [
{ "locale": "en", "value": "Example" },
],
"details": [
{ "locale": "en", "value": "An Example is here" },
]
}
There's also a sub-case, where the documents have a further deeper structure,
which repeats the names and details structure, these would also be
filtered in an ideal world:
{
"_id": "002bafd55b353692a7ab2968074310cc2cbff258",
"_rev": "1-bc853056ac61d817ae3c4ecb4f81322b",
"names": [ ... snip ... ],
"details": [ ... snip ... ]
"deeper": {
"names": [
{ "locale": "en", "value": "Sub-Example" },
],
"details": [
{ "locale": "en", "value": "The Sub-Example is here" },
}
}
I also note that this might not be a view, but rather a show, from the
documentation couchdb says that a show is for transforming documents into any
format.
The final query from a beginner is whether there's some way to make it easier
to work on couchdb views and design docs, right now I'm experimenting with
erica which feels like overkill as I'm
pretty sure I don't want a couch app, I just want to easily maintain my views
in files on the disk, and sync them with the couch database whenever I've made
significant enough changes.
I was able to implement this using a show function, I implemented two show functions, one for convenience:
(doc, req) ->
all_locales = []
for name in doc.names
all_locales.push name.locale
toJSON(all_locales)
(I also implemented it on details, and remove duplicate locales in my real code)
This allows me to do the following:
GET /_design/dbname/_show/list_locales/c0db9ad..snip..
and returns ["en", "de", "fr"], for example - whatever locales the language happens to have.
I can then follow up with the function to retrieve the filtered document:
(doc, req) ->
locales = req.query.locales.split(",")
doc.names = doc.names.filter (name) ->
locales.indexOf(name.locale) > -1
doc.overviews = doc.details.filter (overview) ->
locales.indexOf(overview.locale) > -1
return toJSON(doc) + "\n"
The usage pattern for this is:
GET /_design/dbname/_show/restrict_locales/c0db9ad..snip..?locales=en,fr
GET /_design/dbname/_show/restrict_locales/c0db9ad..snip..?locales=fr
GET /_design/dbname/_show/restrict_locales/c0db9ad..snip..?locales=en,fr,de,it,hu,zh
It works quite remarkably well, and was much faster than I expected. I believe the show function results are aggressively cached by CouchDB.

Resources