So I want to implement a for loop in Jekyll with a variable to the _data file, kinda like
{% for person in site.data.{{ page.base }}.persons %}
{{ person.name }}
{% endfor %}
In this case {{ page.base }} is set to build, I also need it to be set to program, manage, and web. And all these variables are defined in my build.md or program.md and so on.
I have my for loop in the _layouts folder. I've tried using the [page.base] method but it's not working. Here is my code:
---
layout: default
---
<div class="column-wrapper">
<div class="grid-x">
<div class="large-6 shrink cell">
<header class="post-header">
<h1 class="post-title">{{ page.title | escape }}</h1>
<div class="no-image-column-wrapper">
<p class="indent">{{ page.description }}</p>
</div>
</header>
</div>
<div class="large-6 shrink cell">
{% include slideshow.html %}
</div>
{% for person in site.data.build.persons %}
<div class="large-6 shrink cell">
<div class="team-image">
<img src="/images/{{ page.base }}/{{ person.name }}.jpg">
</div>
<style type="text/css">
.team-image {
margin-bottom: 4.5rem;
margin-top: 2rem;
max-height: 1rem;
max-width: 16rem;
margin-right: 10rem;
margin-left: 10rem;
padding-bottom: 5rem;
}
</style>
</div>
<div class="large-6 shrink cell">
<div class="no-image-column-wrapper">
<div class="team-bio">
<h3>{{ person.name }}</h3>
<br>
<p>What grade are you in? <strong>{{ person.grade }}</strong></p>
<p>What is your role in robotics? <strong>{{ person.role }}</strong></p>
<p>What is your favorite ice cream? <strong>{{ person.fav }}</strong></p>
<p>What would you like to major in? <strong>{{ person.major }}</strong></p>
<p>What is your biggest pet peeve? <strong>{{ person.pp }}</strong></p>
<p>What is your spirit animal? <strong>{{ person.sa }}</strong></p>
<p>Why are you intrested in robotics? <strong>{{ person.intrest }}</strong></p>
<style type="text/css">
.team-bio {
padding-bottom: 5rem;
}
</style>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
This is my build.md YAML, (I think it's YAML).
---
title: Build Team
layout: team
permalink: /teams/build/
base: build
path: images/build/pic
description: The build team is dedicated to building the robot.
---
This can be simpler. This could be your persons.yml:
- name: Tom
teams:
- build
- program
- name: Violet
teams:
- program
This could be your Liquid:
{% for person in site.data.persons %}
{% if person.teams contains page.base %}
{{ person.name }}
{% endif %}
{% endfor %}
Related
I am working on CS50 Project 2 and have a webpage that displays active listings. I want to add some changes to the css, but it nothing happens when I add changes to the style in the head, but inline styles work. How do I make it work in the head style?
{% extends "auctions/layout.html" %}
<head>
{% block style %}
<style>
.text {
font-size: 10%;
}
</style>
{% endblock %}
</head>
{% block body %}
<h2>Active Listings</h2>
{% for listing in listings %}
<img src ="{{ listing.image }}" style = "height: 10%; width: 10%;">
<h4 class = "text" style = "color: aqua;">{{ listing.title }}</h4>
<h6>Description: {{ listing.description }}</h6>
<h6>Category: {{ listing.category }}</h6>
<h6>Price: ${{ listing.bid }}</h6>
{% endfor %}
{% endblock %}
This is the code. The font size doesn't change, but it will change colors because of the inline style.
If I add the color style to the head style, not in the inline, nothing happens. This is that code.
<head>
{% block style %}
<style>
.text {
font-size: 50%;
font-family: fantasy;
color: aqua;
}
</style>
{% endblock %}
</head>
{% block body %}
<h2>Active Listings</h2>
{% for listing in listings %}
<img src ="{{ listing.image }}" style = "height: 10%; width: 10%;">
<h4 class = "text">{{ listing.title }}</h4>
<h6>Description: {{ listing.description }}</h6>
<h6>Category: {{ listing.category }}</h6>
<h6>Price: ${{ listing.bid }}</h6>
{% endfor %}
{% endblock %}
In this code the style does not change at all.
This is the html code that is rendered.
{% block body %}
<h2>Active Listings</h2>
{% for listing in listings %}
<img src ="{{ listing.image }}" style = "height: 10%; width: 10%;">
<h4 class = "text">{{ listing.title }}</h4>
<h6>Description: {{ listing.description }}</h6>
<h6>Category: {{ listing.category }}</h6>
<h6>Price: ${{ listing.bid }}</h6>
{% endfor %}
{% endblock %}
Because this is a Django template, you can link a stylesheet stored in a static file folder. This link is a video that explains how to do it.
When I need to use a lot of {%include%} (content) in html templates - do unnecessary extensions appear for each content inclusion? Effects are also applied to each subsequent inclusion of content...
When I can add content inclusion to the first html template expander, everything is fine.
But when I use "pagination" I need to send "page=posts" to paginator.html. I can't find a way to send this variable to blog.html from layout.html...
And I think that in the future I will have the same problems, and therefore it should be solved.
layout.html
<div class="container body-content">
<div id="content">
{% block content %}
{% endblock %}
</div>
</div>
<div class="container body-content">
<footer>
<hr/>
<p>© {{ year }}. Сайт</p>
</footer>
</div>
blog.html
{% extends "app/layout.html" %}
<!--♕-->
{% block content %}
<h2>{{ title }}</h2><br>
{% for post in posts %}
<hr>
<div class="">
<h2> {{post.title}} </h2>
<p> {{post.posted}} </p>
</div>
<p>
{{ post.description }}
</p>
{% endfor %}
{% include "app/pagination.html" with page=posts %}
{% endblock %}
pagination.html
{% extends "app/blog.html" %}
<!--♕-->
{% block content %}
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
Предыдущая
{% endif %}
<span class="current">
Страница {{ page.number }} из {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
Следующая
{% endif %}
</span>
</div>
{% endblock %}
The pagination should be a file that only renders pagination content, not the template around this.
This thus means that you implement the pagination without the {% extends "app/layout.html" %}, so:
{# pagination.html, no extends or block #}
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
Предыдущая
{% endif %}
<span class="current">
Страница {{ page.number }} из {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
Следующая
{% endif %}
</span>
</div>
This will prevent the pagination.html to render headers, footers, and other content. You can then simply import the pagination as a utility template.
I'm using liquid to add content for two <p> inside the column-right <div>:
<div class="page-width">
{% capture image_layout %}
<div class="feature-row__item feature-row__image-wrapper">
{% if block.settings.image != blank %}
<div class="feature-row__image feature-row__image--{{ block.id }} lazyload" data-sizes="auto" data-bgset="{% render 'bgset', image: block.settings.image %}"></div>
<noscript>
<div class="feature-row__image feature-row__image--{{ block.id }}" style="background-image: {{ block.settings.image | img_url: 'master' }}"></div>
</noscript>
{% else %}
<div class="feature-row__image feature-row__image--{{ block.id }}">{{ 'image' | placeholder_svg_tag: 'placeholder-svg' }}</div>
{% endif %}
<div class="column-right">
{%- if block.settings.text != blank -%}
<p class="column-right__text">{{- block.settings.text -}}</p>
{%- endif -%}
{%- if block.settings.smalltext != blank -%}
<p class="column-right__smalltex">{{- block.settings.smalltext -}}</p>
{%- endif -%}
</div>
</div>
{% endcapture %}
But, at the frontend, I get four <p>:
<div class="column-right">
<p class="column-right__text"></p>
<p>We are a bunch of passionate people</p>
<p></p>
<p class="column-right__smalltex"> you can focus on what really matters, potato chips</p>
</div>
Screenshot here
Anybody knows why this happened??
Finally I found out that it was an id problem. It seems that other block had the same id, so it would render one <p> for each block!
Hi I want to put the login form in the login.html which created by 'bootstrap/wtf.html. But the form of username password et al aligned left as the following image. I want to put the form in the center.
The code is following:
{% extends "common/base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{#{% import "macros/_patination.html" as page_macros %}#}
{#<link rel="stylesheet" href="/static/style.css" type="text/css">#}
{% block content %}
<div class = "main-login">
<h1>{{ _('Sign In') }}</h1>
<div class="main-form">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
</div>
<br>
<p>{{ _('New User?') }} {{ _('Click to Register!') }}</p>
<p>
{{ _('Forgot Your Password?') }}
{{ _('Click to Reset It') }}
</p>
</div>
and css style code:
.main-login{
padding-top: 100px;
text-align: center;
}
.main-form{
/*padding-top: 100px;*/
text-align: center;
/*display: inline-block;*/
}
All you have to do is change the section of code:
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
to
<div class="col-md-4 col-lg-offset-4">
{{ wtf.quick_form(form) }}
</div>
And you should be good.
I've got the following Jekyll index
---
layout: default
title: My favourite sandwiches
---
<section class="home">
{% for post in site.posts %}
<article class="column">
<img src="{{ post.image }}">
{{ post.title }}
</article>
{% endfor %}
</section>
My site will have 3 articles (blocks) next to each other, like tiles.
However, I would like to add a class on the first and third article tag so I can add different styling.
I wanted to know how to add this behaviour and if there is a way to index something eg. class="first" if index == 3/1
The html I wanted is to look something like this
<section class="home">
<article class="column first">
<img src="images/bigsandwich.jpg">
My big sandwich
</article>
<article class="column">
<img src="images/icecreamsandwich.jpg">
Icecream sandwich
</article>
<article class="column last">
<img src="images/sushisandwich.jpg">
Sushi sandwich
</article>
</section>
Thanks you for your patience and time.
Liquid's for loops have helper variables available, like forloop.first and forloop.last. See documentation here.
In your case, I would try:
---
layout: default
title: My favourite sandwiches
---
<section class="home">
{% for post in site.posts %}
{% if forloop.first %}
<article class="column first">
{% elsif forloop.last %}
<article class="column last">
{% else %}
<article class="column">
{% endif %}
<img src="{{ post.image }}">
{{ post.title }}
</article>
{% endfor %}
</section>