Insertion of language definition data yml is not being parsed into another datafile before or after presentation.
I've tried using liquid tags.
front-end code presentation
<div class="small-6 medium-3 large-3 columns">
{% for network_item in site.data.network %}
{% if forloop.first == true %}
<h5 class="shadow-black">{{ network_item.menu_name }}</h5>
{% endif %}
{% endfor %}
This is the data file for network.yml still a WIP:
- menu_name: "{{ site.data.language.menu_name }}"
- name: "Icons by Daniel Bruce"
url: "http://entypo.com/"
class: "network-entypo"
title: "Icons by Daniel Bruce"
- name: "Built on Foundation"
url: "http://foundation.zurb.com/"
class: "services-newsletter"
title: "Built on Foundation"
- name: "Images by Unsplash"
url: "http://unsplash.com/"
class: "rss-link"
title: "Images by Unsplash"
- name: "Using Backstretch by Scott Robbin"
url: "http://srobbin.com/jquery-plugins/backstretch/"
class: "sitemap-link"
title: "Using Backstretch by Scott Robbin"
Here's the language item from language.yml
menu_name: "Credits"
In the front-end rendered code I'm getting a title of:
{{ SITE.DATA.LANGUAGE.MENU_NAME }}
This should be the language definition so I can make this theme multilingual.
Related
I have a strange problem where adding collections and collections_dir allows me to get one result where I can view the collection results on the ML Projects page that you can see in the sidebar of my website but it prevents any posts in _posts from rendering.
After doing some research I learned that posts is a collection by default, but I'm not sure how this helps me. I tried moving the _posts directory into the _projects directory, which is my collections_dir, but that does not work.
To replicate issue:
Clone the repo at https://github.com/luke-anglin/lukes_site
Build and serve the site, noting that posts do render
Go to _config.yml and remove the comments on line 26-29 which specify the collection and the collections_dir
Rebuild and see that the posts disappear, but the collection things work.
config.yml
# Dependencies
markdown: kramdown
# Permalinks
permalink: pretty
# Setup
title: Luke Anglin
tagline: Computer Science and Engineering Student
description: Software Engineering, DevOps, Data Science
url: http://localhost:4000/
baseurl: /
author:
name: Luke Anglin
# url: https://twitter.com/mdo
plugins:
- jekyll-paginate
paginate: 5
paginate_path: 'page:num'
# Custom vars
# Collections
# collections:
# - ml
# collections_dir: _projects
version: 2.1.0
github:
repo: https://github.com/luke-anglin/lukes_site
defaults:
- scope:
path: 'static/assets/media'
values:
image: true
index.html where the posts are supposed to be looped through
---
layout: default
title: Home
---
<div class="posts">
{% for post in paginator.posts %}
<div class="post">
<h1 class="post-title">
<a href="{{ post.url }}">
{{ post.title }}
</a>
</h1>
<span class="post-date">{{ post.date | date_to_string }}</span>
{{ post.content }}
</div>
{% endfor %}
</div>
<div class="pagination">
{% if paginator.next_page %}
<a class="pagination-item older" href="{{ site.baseurl }}page{{paginator.next_page}}">Older</a>
{% else %}
<span class="pagination-item older">Older</span>
{% endif %}
{% if paginator.previous_page %}
{% if paginator.page == 2 %}
<a class="pagination-item newer" href="{{ site.baseurl }}">Newer</a>
{% else %}
<a class="pagination-item newer" href="{{ site.baseurl }}page{{paginator.previous_page}}">Newer</a>
{% endif %}
{% else %}
<span class="pagination-item newer">Newer</span>
{% endif %}
</div>
Any other info can be found in the repo. Let me know if there are any other questions.
Try to remove the leading '_' from '_projects' directory. The 'collections_dir:' isn't allowed to have this character in the name of the target folder.
See: https://jekyllrb.com/docs/collections/
Particularly the red notice labeled 'Be sure to move drafts and posts into custom collections directory'. At the end it mentions 'Note that, the name of your collections directory cannot start with an underscore (_).'
Hope this helps.
I have the following in my _config.yml file:
collections:
nr_qa:
output: true
permalink: /:collection/:name
title: 'Node-RED Questions and Answers'
descriptions: 'Node-RED is a flow-based (visual) programming tool. These pages have some information that may be currently missing from the documentaiton.'
github_pages:
title: 'GitHub Pages and Jekyll/Liquid'
description: 'Hints and tips on using Jekyll for publishing to GitHub Pages.'
output: true
permalink: /:collection/:name
and I want to create an automatic index for my collections. So I use code like this:
## {{ site.collections.github_pages.title }}
{{ site.collections.github_pages.description }}
<ul>
{% for item in site.github_pages %}
<li>
{{ item.title | replace:'_',' ' }}
<p>{% if item.description %}
{{ item.description }}
{% else %}
{{ item.excerpt | strip_html }}
{% endif %}</p>
</li>
{% endfor %}
</ul>
And yes, I know I've rather mixed up my markdown and html there. Not relevant to this question.
The problem is that {{ site.collections.github_pages.title }} and {{ site.collections.github_pages.description }} don't render anything even though I think they should.
Can anyone point out my mistake please?
The problem is that title and description should be included in each collection, and not in _config.yml.
Check out Accessing Collection AttributesPermalink for further details.
update
title can be present in each collection metadata in _config.yml. The problem is how you are accessing those variables.
One approach is to have a specific layout for each collection, then you can access them like:
{% assign col = site.collections | where: 'label','github_pages' | first%}.
TITLE: {{ col.title }}.
DESCRIPTION: {{ col.description }}.
I have created a data file with images which I use normally for posts.
ImageKey:
- url: "/assets/logos/Image.png"
title: "Image Title"
Now I want to use this image paths in my post headers.
---
layout: page
image:
- site.data.images.ImageKey
---
And my HTML looks like
{% for image in page.images %}
<div>
<div class="img-thumbnail">
<img class="img-responsive" src="{{site.baseurl}}{{image.url}}" alt="{{image.title}}">
</div>
</div>
{% endfor %}
But anything is wrong here. There will no picture be rendered.
It works if I use values in the fronter matter directly.
---
layout: page
image:
- url: "..."
title: "..."
---
I have the problem / request solved.
My _data\images.yml looks like
Image_Key_Name
url: /assets/file.png
alt: ....
title: ....
copyright: ....
My _posts\postXYZ.md
---
layout: post
author: Ben
titleImages:
- Image_Key_ Name
- Another_Image_Key_Name
abc...
---
And my _layouts\post.html
now iterates over the keys and uses them as array index.
<div class="title-images">
{% for titleImageKey in page.titleImages %}
{% assign titleImage = site.data.images[titleImageKey] %}
<img src="{{site.baseurl}}{{titleImage.url}}" alt="{{titleImage.title}}" />
{% endfor %}
That's it!
I have a list of courses to take using this courses.yml
- title: Basic Residential HSI Install
code: OSP0000111
description: Install and Repair residential and business class POTS, HSI, and Video services
newhire: true
skillset: Copper
jobtype: CST
advanced:
- title: PTA Testing Overview
code: OSP0000114
description: Teaches the technician how to close out a T1 test using the PTA system
newhire: false
skillset: Systems
jobtype: CO
advanced: no
- title: Technician Billing
code: OSP0000112
description: Teaches the technician how to properly bill the customer
newhire: false
skillset: Copper
jobtype: CST
advanced: yes
- title: Central Office Jumper
code: OSP0000113
description: Teaches the technician how to run jumpers
newhire: true
skillset: Copper
jobtype: CO
advanced: no
and I list the courses using:
<ul>
{% for teds in site.data.courses %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code}} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
This works just fine. However, now I want to create a list using the same data file, of only those courses where the newhire variable is "true".
I have not understood any previous document that explains how to do this. I've tried a where clause and filter to no avail.
Any ideas?
Per https://jekyllrb.com/docs/templates/ website, I tried adding the where clause:
<ul>
{% for new in site.data.courses | where "newhire","true" %}
<li> Course Title: {{ new.title }} <br />
Course Code: {{ new.code }} | Job Type: {{ new.jobtype }} <br />
Description: {{ new.description }} <br />
Schedule
<hr />
</li>
{% endfor %}
</ul>
I refreshed the page and nothing happened. I got the same page, a list of ALL the courses. No filtering. I even restarted Jekyll server. Same result, no filtering.
No errors where noted by the Jekyll server either.
Per your answer, I changed the data file variables. 2ea "0's", 2ea "1's". Then I changed the html file to:
<ul>
{% assign teds = site.data.courses | where: 'newhire', 1 | sort: 'title' %}
{% for teds in courses %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code }} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
The Jekyll server reported no errors but, when I refreshed the page, it displayed none of the data at all. No list of 4 titles, nor 2 liked I hope, just the web page. :(
UGGH, I saw my error when i reviewed it after dinner :)
Here's what worked:
<ul>
{% assign new = site.data.courses | where: 'newhire', 1 | sort: 'title' %}
{% for teds in new %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code }} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
UGGH, I saw my error when i reviewed it after dinner :) A clear head helps!
The correct code was:
<ul>
{% assign new = site.data.courses | where: 'newhire', 1 | sort: 'title' %}
{% for teds in new %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code }} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
Thank you so much, Christian!!
JOE
I can show you a working example from my blog, where I'm doing something similar like you want to achieve.
I think I tried it with true/false in the beginning, but I didn't get it to work, so I used 0/1 instead.
Here's the example:
I have a data file with projects. Each project has a sidebar property which is 0 or 1:
- name: Bitbucket Backup
url: /bitbucket-backup/
logo: /php/cache/img/bitbucket-backup-logo128x128.png
desc: A backup tool which clones all your Bitbucket repositories to your local machine
sidebar: 1
In my layout file, I have a sidebar where I only want to list those projects with sidebar == 1. I'm doing this with the following code:
{% assign projects = site.data.projects | where: 'sidebar', 1 | sort: 'name' %}
{% for project in projects %}
<li>{{ project.name }}</li>
{% endfor %}
Please note that it only works for me when I assign the line with the where clause to a variable (projects) and then loop the variable.
The following does not work:
{% for project in site.data.projects | where: 'sidebar', 1 | sort: 'name' %}
<li>{{ project.name }}</li>
{% endfor %}
I am trying to simply style my active links in Jekyll but have been unsuccessful in getting them working.
Here is the site that I am trying to get them working on: http://concisecss.github.io/concise.css, which you can see the source code for here: https://github.com/ConciseCSS/concise.css/tree/gh-pages.
I am putting this YAML code in my _config.yml to define my top-level navigation:
# Main Navigation
nav:
- text: Welcome
url: /concise.css/
- text: Why Concise
url: /concise.css/why-concise/
- text: Get Started
url: /concise.css/get-started/
- text: Documentation
url: /concise.css/documentation/layout/container/
- text: Add-Ons
url: /concise.css/add-ons/
Then in my header.html include, which is where my navigation is, I have:
{% for link in site.nav %}
<li>
<a {% if link.url == page.url %}class="active"{% endif %} href="{{ link.url }}">{{ link.text }}</a>
</li>
{% endfor %}
However, whenever I am on one of those navigation links, the active class is not added (the link should be pinkish when you are on it.
Everything else is working fine, so I'm assuming it might just be a small issue I'm running into.
Edit: Here is what the front-matter on one of my pages looks like:
---
layout: why-concise
title: Why Concise
permalink: /why-concise/
---
I just did the same thing in my blog project which is not alive yet to show you, but it works like this:
1. create a data file nav.yml file and write your nav text and URLs within a folder _data.
nav.yml
- text: Welcome
url: /concise.css/
- text: Why Concise
url: /concise.css/why-concise/
- text: Get Started
url: /concise.css/get-started/
- text: Documentation
url: /concise.css/documentation/layout/container/
- text: Add-Ons
url: /concise.css/add-ons/
2. In your html page you're going to create a loop through your data menu list from yml file.
{% for nav in site.data.nav %}
<li{% if nav.url == page.url %} class="active"{% endif %}>{{ nav.text }}</li>
{% endfor %}
Just remember to make sure your permalink is the same written in your nav.yml if you have set url:/concise.css/why-concise/ in your nav.yml so your permalink should be the same in the front-matter.
---
layout: why-concise
title: Why Concise
permalink: /concise.css/why-concise/
---
UPDATE:
#Keenan here is an example http://adrianorosa.com, that I told you before.
The source can be found at https://github.com/adrianorsouza/adrianorosa.com