Django display paragraph if nothing found - html

I want that a message gets displayd if no search results are found but somewho im doing it wrong! Is
if post in object_list.count == 0
unsuitable?
My Django template:
{% extends 'quickblog/base.html' %}
{% block content %}
{% if post in object_list.count == 0 %}
<p>No results, sorry :(</p>
{% else %}
{% for post in object_list %}
<div class="post">
<h1><u>{{ post.title }}</u></h1>
<p>{{ post.content|linebreaksbr }}</p>
<div class="date">
<a>Published by: {{ post.author }}</a><br>
<a>Published at: {{ post.published_date }}</a><br>
<a>Category: {{ post.category }}</a><br>
<a>Tag(s): {{ post.tag }}</a>
</div>
</div>
{% endfor %}
{% endif %}

Related

How can I exclude current post from related posts in Jekyll?

My code is:
<div class="recent-posts">
{% for post in site.posts | limit:3 %}
<div class="recent-posts-inline">
{% if post.featured-image %}{% include post-featured-image.html image=post.featured-image alt=page.featured-image-alt %}{% endif %}
<h4>
{{ post.title }}
</h4>
<p>{{ post.excerpt | strip_html | strip_newlines | truncate: 156 }}</p>
<p>Read More...</p>
</div>
{% endfor %}
</div>
I have tried using where_exp filter but to no avail. That's why I have to ask this question again.
Use the page variable in an if-check. Only do something if the post is not the same title as the current page. If you want a different comparison, you can check the .url, .id, or .name.
<div class="recent-posts">
{% for post in site.posts | limit:3 %}
{% if post.title != page.title %}
<div class="recent-posts-inline">
...
{% endif %}
{% endfor %}
</div>

Adding tags to jekyll hyde blog

I am trying to add tags to my blog based on jekyll hyde.
This is what I have in place right now.
_includes/filter_by_tag.html
<div class="message">
Filter by tag:
{% assign all_tags = site.data.tags %}
{% for tag in all_tags %}#{{ tag[1].name }}
{% endfor %}
</div>
_includes/tags_for_page.html
{% assign post = page %}
{% if post.tags.size > 0 %}
{% capture tags_content %}{% if post.tags.size == 1 %}<i class="fa fa-tag"></i>{% else %}<i class="fa fa-tags"></i>{% endif %} {% endcapture %}
{% for post_tag in post.tags %}
{% assign tag = site.data.tags[post_tag] %}
{% if tag %}
{% capture tags_content_temp %}{{ tags_content }}#{{ tag.name }} {% if forloop.last == false %}<!--comma-->{% endif %}{% endcapture %}
{% assign tags_content = tags_content_temp %}
{% endif %}
{% endfor %}
{% else %}
{% assign tags_content = '' %}
{% endif %}
_layouts/blog_by_tag.html
---
layout: default
---
{% assign tag = site.data.tags[page.tag] %}
<div class="page">
<h1 class="page-title">Articles by tag: #{{ tag.name }}</h1>
<div class="message">
All tags:
{% assign all_tags = site.data.tags %}
{% for tag in all_tags %}#{{ tag[1].name }}
{% endfor %}
</div>
<div>
{% if site.tags[page.tag] %}
{% for post in site.tags[page.tag] %}
{{ post.date | date_to_string }} » {{ post.title }}<br>
{% endfor %}
{% else %}
<p>There are no posts for this tag.</p>
{% endif %}
</div>
</div>
_layouts/post.html
comments: true
---
{% include tags_for_page.html %}
<div class="post">
<h1 class="post-title">{{ page.title }}</h1>
<span class="post-date">{{ page.date | date_to_string }} {{ tags_content }}</span>
{% if page.cover_image %}
<img src="{{ page.cover_image }}" alt="{{ page.title }}">
{% endif %}
{{ content }}
</div>
archive.md
title: Blog Archives
{% include filter_by_tag.html %}
{% for post in site.posts %}{{ post.date | date_to_string }} » [ {{ post.title }} ]({{ post.url }})
{% endfor %}
I am not sure where am I going wrong here, I tried following the content from this blog post here, tried replicating the same for my blog but I can't see the tags being generated and displayed.
Not sure where am I going wrong.
Link to my blogs github repo where I am trying to add tags
link to the blog where you can see the blog.
Commit hash where I tried adding the tags
I had missed out the file
_data/tags.yml
whose contents would be like
ansible:
name: ansible
apache:
name: apache
and so on

How to check amount of posts?

I have this code:
---
layout: default
---
<hr>
{% assign posts_amount = site.posts.length %}
{% if posts_amount == 0 %}
<h2>Sorry :(</h2>
<p>At the moment, content isn't available for you. Check me later!</p>
<hr>
{% else %}
{% for post in site.posts %}
<h2>
{{ post.title | escape }}
</h2>
<p>{{ post.date | date: "%Y-%m-%d" }}</p>
<hr>
{% endfor %}
{% endif %}
<p>Subscribe via RSS.</p>
but it's not working, I don't know why.
Jekyll: newest version (3.6.2), with jekyll-feed (0.9.2), and jekyll-seo-tag (2.3.0).
Any ideas?
You can use dot notation and you don't need the assign
---
layout: default
---
<hr>
{% if site.posts.size == 0 %}
<h2>Sorry :(</h2>
<p>At the moment, content isn't available for you. Check me later!</p>
<hr>
{% else %}
{% for post in site.posts %}
<h2>
{{ post.title | escape }}
</h2>
<p>{{ post.date | date: "%Y-%m-%d" }}</p>
<hr>
{% endfor %}
{% endif %}
<p>Subscribe via RSS.</p>

Trying to nest if statements in Jekyll/Liquid

having trouble nesting the following code. Where am I going wrong?
I just want to have some events show if the day is monday and then within that each event has a number of stars so I want to have another if statement that pulls that amount of stars and displays the correct image.
Here is my code.
<div class="row">
{% for event in site.nottingham_events %}
{% if event.day == "Monday" %}
<div class="event-guide-event">
<img class="event-guide-event--thumbnail" src="/img/thumb.jpg"
alt="">
<h2>{{ event.name }}</h2>
<p>When: {{ event.time }}</p>
<h3>Where: {{ event.bar }}</h3>
<h3>Hosted By: {{ event.brand }}</h3>
{% if event.stars =="3" %}
<img src="/img/events/3-stars.png" alt="Everyone">
{% endif %}
{% if event.stars =="2" %}
<img src="/img/events/2-stars.png" alt="Enthusiasts and
Beginners">
{% endif %}
{% if event.stars =="1" %}
<img src="/img/events/1-star.png" alt="Expert">
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
I resolved it by changing my logic, because you can't nest if statements in Liquid.

Jekyll blog posts on non index.html pages

I have used the below code snippet from the Jekyll website to paginate Jekyll plog posts on my index.html page:
<div class="container">
<ul class="post-list">
<!-- This loops through the paginated posts -->
{% for post in paginator.posts %}
<h1>{{ post.title }}</h1>
<p class="author">
<span class="date">{{ post.date }}</span>
</p>
<div class="content">
{{ post.content }}
</div>
{% endfor %}
{% if paginator.total_pages > 1 %}
<div class="pagination">
{% if paginator.previous_page %}
« Prev
{% else %}
<span>« Prev</span>
{% endif %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
<em>{{ page }}</em>
{% elsif page == 1 %}
{{ page }}
{% else %}
{{ page }}
{% endif %}
{% endfor %}
{% if paginator.next_page %}
Next »
{% else %}
<span>Next »</span>
{% endif %}
</div>
{% endif %}
</ul>
</div>
However when I try to add this to a /pages/Blog.html page it does not work. It does not show any of the posts in my _posts directory and instead produces and empty container. I am assuming it is a path issue.
I have added the YAML header to the Blog.html file as required. When page is rendered it produces an empty container.
If you want an url that looks like /pages/Blog/ for your posts listings :
activate pagination by setting a paginate: 5 in _config.yml
set paginate_path: pages/Blog/page:num in _config.yml
rename /pages/Blog.html to pages/Blog/index.html