Shopify custom text field print in front-end - json

I have added custom text field inside layout header using json :
{
"type": "text",
"id": "my_text",
"label": "MyText"
}
Then I have called it inside luquid file like this:
{% if settings.my_text%}
<li class="test">{{ 'layout.header.my_text' }}</li>
{% endif %}
In return I'm getting same (layout.header.my_text ) not the value which I added from customizer

So the solution is I changed : layout.header.my_text to settings.my_text .

Related

Hugo Data Templates: Where to create files and what to put in them?

I have a Hugo SSG website.
My JSON file is saved in: /data/source.json
I created a template file: /layouts/test.html that has this content:
<!-- Data is in /data/source.json -->
{{ range .Site.Data.source }}
{{ range .names }}
<!-- person_name -->
<p>{{ .identifier.person_name }}</p>
{{ end }}
{{ end }}
How do I render this .html content to the website?
The Hugo documentation here doesn't explain what I need to do after making the .html file.
It looks like you have two range operations when you need only one. You are not ranging over multiple source.json files, correct?
Assuming you have a file data/source.json like this:
{
"names": [
{
"identifier": {
"person_name": "Joe Wilson"
}
},
{
"identifier": {
"person_name": "Nancy Wilson"
}
}
]
}
Then it should be possible to render those names like this:
{{ range .Site.Data.source.names }}
<p>{{ .identifier.person_name }}</p>
{{ end }}
Add that to a layout in your themes/{theme-name}/layouts and it will render on the pages using that template.

Locales/literals containing html

In
locale/lang.json I have
{
"title": "Title",
"image": "service-corporate_thumb-v2.jpg",
"alt": "alt",
"imageFooter": "Some caption %",
"imageFooterCTA": "author",
"imageFooterURL": "https://example.com/author",
},
I'm trying to generate the author like, like so:
<img :src="require(`~/assets/img/services/${service.image}`)" :alt="service.alt" class="mb-8">
<p>{{ service.imageFooter.replace('%', `${service.imageFooterCTA}`) }}</p>
But this prints out in the generated HTML:
{{ service.imageFooter.replace('%', `${service.imageFooterCTA}`) }}
How can I generate html inside the {{ expresion }} ?
You need to use v-html for generating html in a template.
More info here.
For your example try this
<p class="mb-8">
<a v-html="service.imageFooter.replace('%', '$' + service.imageFooterCTA + '')">
</p>
Notes:
the tag that has a v-html directive will be replaced, so you could use anything, not only a
the value for v-html needs to be valid JS code that will be executed in the current context. This the reason I treated the tag inside as a string and removed the interpolation {.

How do I make JSON data file objects use a layout

First, I'm using GitHub Pages dependencies.
I'm trying to make use of Jekyll's data files, but I'm having problem making functional links that would use a layout to display more of the object's contents.
I can access the page via the url: http://127.0.0.1:4000/dev/ - and my for loop at ./dev/index.html shows as it should. If I click any links on that page I get a 404 message because e.g: http://127.0.0.1:4000/dev/parent/child couldn't be found.
The posts in Jekyll use Front Matter to determine which layout it should use, but I don't know how to make my links to use my custom layout when I click any of the links in ./dev/index.html.
How can I create a "link" between the urls in ./dev/index.html to display the ./_layouts/post.html?
Here's what I got so far.
./_data/dev.json:
[
{
"id": 0,
"name": "I am (g)Root",
"link": "parent",
"data": [
{
"id": 0,
"name": "Some kid",
"content": "bla bla bla",
"link": "child"
},
{
"id": 1,
"name": "A desk",
"content": "texty texty",
"link": "desk"
}
]
}
]
./dev/index.html
---
layout: page
title: 'dev'
published: true
date: 2015-10-03 18:48:58 +02:00
category: 'module'
---
{% assign data = site.data.dev.first %}
{% for post in data.data %}
<ul>
<!-- URL will look like this: /parent/child -->
<li>{{ post.name }}</li>
</ul>
{% endfor %}
./_layouts/post.html
---
layout: default
---
{{ content }}
./_config.yml
permalink: /:categories/:title
Data files are just datas that you can consume in loops. Without a generator plugins you're not able to generate pages from them.
In order to generate page from "datas" you can use collections.

Read a filename from json and include it by jekyll

Let you assume that I have this json file:
{
"components":[
{
"id" : "brandbar",
"name" : "brandbar.html",
"type":"navbar",
"description":"Bar with the brand",
"status": "draft"
},
{
"id":"topbar",
"type":"navbar",
"component":"Best brand",
"description":"Chart with Date"
}]
}
Now, I would like to have a loop on this json to retrieve the filenames.
{% for entry in site.data.component.components %}
<div class="col-md-12">
{% include {{ entry.name }} %}
</div>
{% endfor %}
The problem is that I can't use {{ entry.name }} in my include statement.
is there a way to achieve this goal ?
I don't want to loop directly in my folder... I would like to have a main file where I will fill in every important attribute about the components.
You can try to indent you json with spaces instead of tabs.
This might do the trick :
{"components":[
{
"id" : "brandbar",
"name" : "brandbar.html",
"type":"navbar",
"description":"Bar with the brand",
"status": "draft"
},
{
"id":"topbar",
"type":"navbar",
"component":"Best brand",
"description":"Chart with Date"
}
]}
Except that topbar has no name propriety, and this can cause an error.

Right way to use the data in Jekyll

The goal is to use the variables defined in the front-matter section in a particular page.
Here my structure of the file system:
_Components
c1.html
c2.html
Here I have defined the attributes in the front-matters.
_Includes > Components
c1.html
Here I want to use a loop to refer to a variable defined in the _Components > c1.html page.
How can I achieve this goal ?
In my _Includes > Components > c1.html I have the following code:
<body class="full">
{% assign fullcomponents = site.components %}
{% for component in fullcomponents | where:"title","c1html" %}
{% component.title %}
{% endfor %}
<div class="container-fluid" id="componentscontainer">
<div class="col-md-12">
<div class="panel panel-primary" id ="panelcomponentlarge">
<div class="panel-heading" >
Chart C3 Line
</div>
etc...
Surely I'm missing some trivial things.
SECOND ATTEMPT
I figured out that I can provide a data layer for that so, I tried to split this information into a new data file.
Here the content of components.json
{
"Components": [
"ChartC3Line":{
"component":"ChartC3Line",
"description":"This is an attempt"
},
"ChartC3Lines":{
"component":"ChartC3Lines",
"description":"This is an attempt"
}
]
}
And I'm trying to get this information with the following code:
{% assign comp = site.data.components.Components[ChartC3Line] %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>
but anything is coming up.
THIRD ATTEMPT
I found a solution but I don't like it at all here my new json file
{
"ChartC3":[
{
"component":"ChartC3Line",
"description":"This is an attempt"
}],
"ChartC4":[
{
"component":"ChartC3Line",
"description":"This is an attemptSSSSSSS"
}]
}
I don't want to have an object of several arrays of one element!
Here the code to retrieve the right information:
{% assign comp = site.data.components.ChartC4[0] %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>
SOLVED
Following the structure of a json file, I changed my structure in an easier way:
{
"ChartC3":
{
"component":"ChartC3Line",
"description":"This is an attempt"
},
"ChartC4":
{
"component":"ChartC3Line",
"description":"This is an attemptSSSSSSS"
}
}
Now I can easily have access to the right object.
{% assign comp = site.data.components.ChartC3 %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>