Include the whole post, not only summary. Jekyll - jekyll

I have a very noob question. I want to create a page, where will be presented all posts from some category. I understand, that I should write some {% include %} tag, but I could not understand which.
I have:
{% for post in site.posts %}
<!-- check if post comes from one of page categories-->
{% assign PostAndPageCategories= page.categories | concat: post.categories %}
{% capture all_cat %}{{ PostAndPageCategories | join: "," }}{% endcapture %}
{% capture unique_cat %}{{ PostAndPageCategories |uniq | join: "," }}{% endcapture %}
{% if all_cat != unique_cat %}
<!-- END check if post comes from one of page categories-->
{% include archive-single.html %}
{% endif %}
{% endfor %}
Obviously, this code shows me posts with teasers, but I need to display the whole post.
How should I change line {% include archive-single.html %}?

I found {{post.content}} instead of {% include archive-single.html %} work fine for me.

Related

Jekyll/Liquid Relative URL filter breaks links

I'm trying to use relative_url in most of the links of my Jekyll theme, so if someone wants to have this theme working in a subdirectory he can do it.
I have a problem with the list of categories of the post, each of which should link to the archive.
In _layouts/post.html I have this code:
{% if site.data.settings.categories.active %}
{% include categories.html %}
{% endif %}
categories.html has this code:
<div class="categories">
<span><p>Categories:</p>
{% if post %}
{% assign categories = post.categories %}
{% else %}
{% assign categories = page.categories %}
{% endif %}
{% for category in categories %}
{{category}}
{% unless forloop.last %} {% endunless %}
{% endfor %}
</span>
</div>
Here's the problem:
{{category}}
Somehow, this returns the current post url.
{{category}}
This returns the correct link, but does not work in case the site is in a subdirectory.
Why it returns the post url?
There are multiple problems here.
First off, Liquid doesn't evaluate nested constructs.
Therefore, the following code:
{{ "/categories/#{{category | slugify}}" | relative_url}}
needs to be rewritten into:
{% capture url %}/categories/{{ category | slugify }}{% endcapture %}
{{ url | relative_url }}
Secondly, there is no global post object. Therefore {% if post %} is always going to evaluate to a negative. i.e., it is redundant.

how to displayliquid code in Jeckyll post

Hello I am trying to make a post using jeckyll and as part of my post I would like to show some liquid code. The post should display the IF statement as part of the post text (example below).
{% if customer and customer.tags contains 'Wholesale' %}
{% endif %}
I have tried to post this as
{% highlight liquid %}
{% if customer and customer.tags contains 'Wholesale' %}
{% endif %}
{% endhighlight %}
and also
{% highlight markdown %}
{% if customer and customer.tags contains 'Wholesale' %}
{% endif %}
{% endhighlight %}
but anything I try seems to be still executing the liquid code.
Is there a way to display the IF statement my post?
Try wrapping your liquid code in {% raw %} {% endraw %} like this:
{% highlight liquid %}
{% raw %}
{% if customer and customer.tags contains 'Wholesale' %}
{% endif %}
{% endraw %}
{% endhighlight %}
The raw tag will disable any liquid processing and output your code as desired.

How to check if a value is present in a list?

I would like to get the list of posts having a specific tag in their front matter (*)
I tried the code below, which iterates over all the tags of the current post pages (the current tag is t), then iterates over all the posts (p) to check if they have this tag (and just outputs the title, for debugging reasons):
{% for t in page.tags %}
{% for p in site.posts %}
{% if t in p.tags %}
{{ p.title }}
{% endif %}
{% endfor %}
{% endfor %}
The line {% if t in p.tags %} seems to fail (I come form a Python background so I gave it a try) and I cannot find the in operator in liquid. Does it exits?
(*) I am mentioning what I want to achieve in case there is a more straightforward way to do that but I am still interested in the general question.
Following your example it can be done with the contains tag:
contains can also check for the presence of a string in an array of
strings.
{% if product.tags contains "outdoor" %}
This product is great for
using outdoors!
{% endif %}
So to get the list of posts having a specific tag in their front matter (in this case the posts with the tag mytag):
{% assign posts_with_mytag = site.posts | where_exp:"item",
"item.tags contains 'mytag'" %}
{% for post in posts_with_mytag %}
{{post.title}}
{% endfor %}
Following-up on #maracuny's answer, the corrected code from my question for completeness:
{% for t in page.tags %}
{% for p in site.posts %}
{% if p.tags contains t %}
{{ p.title }}
{% endif %}
{% endfor %}
{% endfor %}

include_relative post.path jekyll

I'm trying to put a number of related posts on a single page. The problem is that the included posts are all textile pages, using some {% highlight %} tags. When I try to include then via post.content, they don't get textilized (e.g, I see "{% highlight..." on the page).
I've tried a few different things:
This never gets textilized:
{% for post in site.tags.my_tag %}
{{ post.content | textilize }}
{% endfor %}
This (based on http://nateeagle.com/2011/08/31/jekyll-not-parsing-includes/) returns no content:
{% for post in site.tags.apidocs %}
{% capture included_post %}
{{% include_relative post.path %}}
{% endcapture %}
{{ included_post | textilize }}
{% endfor %}
Any ideas?
Bradley
Try
{% include_relative {{post.path}} %}

Getting the related posts from specific category (category/_posts)

I am doing the following
{% for post in site.related_posts limit:3 %}
// My stuff
{% endfor %}
and it keeps returning the posts from each of my categories i.e. blog/_posts/ as well as projects/_posts/ what I want is only blog posts. So I tried to do the following
{% for post in site.categories.blog.related_posts limit:3 %}
// My stuff
{% endfor %}
But it doesn't seem to return anything at all. Can any one please tell me what am I doing wrong here?
I never use related_posts, but this fairly ugly bit might work for you:
capture the category
{% capture related_posts %}{{ page.categories }}{% endcapture %}
Use that category to create your related posts
{% assign collection = site.categories[related_posts] %}
Return the related posts in a loop, pulling out the current page's post
{% for article in collection %}
{% unless page.url == article.url %}
{{ article.title }} - {{ category | capitalize }}<br />
{% endunless %}
{% endfor %}
Both this and related posts are processor intensive if you have a lot of posts.