I have a Jekyll collection document in the collection coding:
---
title: 'iOS iConify'
rawname: iosiconify
image: {{site.img}}/z-iosiconify.png
layout: post
link: https://iosiconify.github.io/
---
Hi!
I'm trying to render all of the documents in the collection coding on an html page, and I have the following code:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}
I'm referencing a lot of my custom front matter variables in it, such as {{ post.rawname }}. However, when the page builds the only part that works is {{ post.content }}.
Here is the rendered HTML:
<tr id="-desktop">
<td id="left">
<a href="" target="blank" id="-desktop-a">
<img src="">
</a>
</td>
<td id="right">
<h2></h2>
<h4><p>Hi!</p>
</h4>
</td>
</tr>
Do you have any idea why none of the custom front matter variables are working and how I can get them to work?
There is an error in Front-matter that prevents Jekyll to correctly processing it, displaying only the content.
This line image: {{site.img}}/z-iosiconify.png should be image: z-iosiconify.png.
Then when displaying the documents preppend site.img like {{ post.image | prepend: site.img }}.e.g.:
{% for post in site.coding %}
<tr id="{{ post.rawname }}-desktop">
<td id="left">
<a href="{{ post.link }}" target="blank" id="{{ post.rawname }}-desktop-a">
<img src="{{ post.image | prepend: site.img }}">
</a>
</td>
<td id="right">
<h2>{{ post.title }}</h2>
<h4>{{ post.content }}</h4>
</td>
</tr>
{% endfor %}
Related
Attached is the wagtail template I have written so far.
{% load wagtailimages_tags %}
<section class="container">
<h2 class="text-center">{{ self.title }}</h2>
<div class="general-alumnae-deck">
{% for member in self.general_member_cards %}
{% if member.photo %}
{% endif %}
{% endfor %}
</div>
</section>
Ultimately I want the code to look like:
<h2>Avatar Images</h2>
<ul>
<li><img src="img_avatar.png" alt="Avatar" class="avatar"> <h3> Bleu </h3></li>
<li><img src="img_avatar2.png" alt="Avatar" class="avatar"> <h3> Red </h3></li>
</ul>
</body>
</html>
with the image popping up next to the "h3" tag if there exists a photo of course the image will be {{}} double bracketed for dynamic template.
It's not clear whether the image is from Wagtail's image library, but if it is, you should use the {% image %} tag. See https://docs.wagtail.org/en/stable/topics/images.html#
{% with self.general_member_cards as cards %}
{% if cards %}
<ul>
{% for member in cards %}
<li>
{% if member.photo %}
{% image member.photo fill-80x80 %}
{% endif %}
<h3>{{ member.name }}</h3>
</li>
{% endfor %}
<ul>
{% endif %}
I have also used a {% with %} tag to cache self.general_member_cards in the template, in case this requires a database query. If it does not, you can skip that step.
You more or less have it already ...
<section class="container">
<h2 class="text-center">{{ self.title }}</h2>
<div class="general-alumnae-deck">
<ul>
{% for member in self.general_member_cards %}
<li>
{% if member.photo %}
{% image member.photo fill-50x50 as avatar %}
<img src="{{ avatar.url }} class='avatar">
{% endif %}
<h3 style="display:inline;">{{ member.name }}</h3>
</li>
{% endfor %}
</ul>
</div>
</section>
You said you wanted image next to the <h3>, so you need to override the display:block property of the h3 tag and make it inline as above (or create a css class for this).
EDIT: Updated to use wagtail's image template tag to get the rendition of the member photo
I am working on a simple web-application with flask and am currently trying to dynamically create a scrollspy list group with jinja. In the code snippet the variable "choices" represents a list of lists of dictionaries. So the variable dict will be a list of dictionaries that populates the ids needed for the list group to work. For simplicity, I am testing it with choices containing only one list of dictionaries and loop.index to create the ids, but I was going to change that to uniquly generated ids later as choices will have more elements.
Unfortunately, the list group does not work properly. Any ideas as to what I'm doing wrong? The browser console throws me an error, "uncaught TypeError: i is null", relating to the bootstrap scrollspy.js. I was not able to trace it back and figure out what causes the error.
{% extends "layout.html" %}
{% block title %}
Results
{% endblock %}
{% block main %}
<!--course display-->
{% for i in choices %}
<div class= "container-fluid">
<div class="row justify-content-center">
<div class="col-9 heading">
<div>
<h1>Coursera Courses</h1>
</div>
</div>
</div>
<div class="row justify-content-center result-background">
<div id="list-example" class="col-2 list-group">
{% for dict in i%}
<a class="list-group-item list-group-item-dark list-group-item-action" href="#list-item-{{ loop.index }}">{{ dict["Course Name"] }}</a>
{% endfor %}
</div>
<div class="col-7">
<div class="scrollspy-example" data-bs-spy="scroll" data-bs-target="#list-example" data-bs-offset="40" tabindex="0">
{% for dict in i %}
<div class="boxlayout" id="#list-item-{{ loop.index }}">
<img src="{{ dict["Image URL"] }}" alt="responsive webite" class="img-thumbnail" align="left" width="15%" height="15%">
<h2>{{ dict["Course Name"] }}</h2>
<details close>
<summary>Lorem ipsum</summary>
Lorem ipsum
</details>
</br>
<table>
<tr>
<td>Manufacturer</td><td> </td>
<tr>
<td>Certificate</td><td>{{ dict["Certificate"] }}</td>
</tr>
<tr>
<td>Costs</td><td>${{ dict["Current Price"] }}</td>
</tr>
<tr>
<td>Landing Page</td>
</tr>
</table>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
The CSS I use as per the Bootstrap requirements:
.scrollspy-example{
position: relative;
overflow-y: scroll;
height: 300px;
}
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!
New to Jekyll. I'm putting together a list view of post categories(review).. The loop works fine, spits out the image, post etc.. but when I try to add the link {{ p.url }} it does not work.. Suggestions?
{% for reviews in site.categories.review %}
<tr>
<th>{{reviews.title}}</th>
<th></th>
</tr>
<td style="width: 33%;"><img style="width: 200px;" src="{{ site.baseurl }}/images/posts/{{reviews.banner_image}}"></td>
<td><strong>{{reviews.category}}</strong>
<ul>
<li>Key Point #1</li>
<li>Key Point #1</li>
<li>Key Point #1</li>
<li>Key Point #1</li>
<li>{{ reviews.tags }}</li>
</ul>
<div class="clear"><input type="submit" value="Learn More..." name="Learn More..." class="button"></div>
</td>
{% endfor %}
</table>
Try to use {{ reviews.url }}.
Instead of : {{ post_url }}
David Recommended: {{ reviews.url }}
It worked.
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>