I am trying to implement disqus and facebook commenting system for different categories in jekyll blog.
Here is my current approach.
{% for category in site.categories %}
{% if category.type == "personal" %}
{% include facebook.html %}
{% else %}
{% include disqus.html %}
{% endif %}
{% endfor %}
Expected result: Facebook comment should be loaded in category personal from facebook.html otherwise disqus comment should be loaded in all other category.
Actual result: Disqus comments loads automatically in personal category regardless of the loop.
What should be changed to make the comments load correctly?
It seems that you want to print disqus or facebook on each page depending on "personnal" category presence.
As #marcanuy says, you have to refer to page.categories, which is an array.
{% if page.categories contains "personnal" %}
{% include facebook.html %}
{% else %}
{% include disqus.html %}
{% endif %}
Category doesn't have a type attribute. Checking directly like:
{% for category in page.categories %}
{% if category == "personal" %}
{% include facebook.html %}
{% else %}
{% include disqus.html %}
{% endif %}
{% endfor %}
Should detect the personal category and load disqus comments.
Related
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.
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.
Maybe this is a case of a Python programmer trying to work with Ruby and maybe this is a "feature" -- I don't know. For the life me I can't figure out how to set state on posts during the rendering process.
I have a _layout that just calls include twice:
{% include templateA %}
{% include templateB %}
templateA walks the posts and renders some of them on the basis of some_condition.
{% for post in site.posts %}
{% if some_condition %}
<!-- Render the post -->
{% assign post.rendered = true %}
{% endif %}
{% endfor %}
templateB attempts to walk the posts and render the rest:
{% for post in site.posts %}
{% unless post.rendered %}
<!-- Render the post -->
{% endif %}
{% endfor %}
This does not work as expected. I have also tried the {% assign post[rendered] = true %} syntax. No errors are thrown; just silent failure.
Where am I failing here? Is my mental model for the rendering process just totally wrong? Thanks!
Your first though was nearly ok. The unless tag does the contrary of if.
But you cannot change jekyll's variables, they are "freezed".
So, this might work :
templateA
{% for post in site.posts %}
{% if same_condition %}
<!-- Render the post -->
{% endif %}
{% endfor %}
With the same condition unless will render posts not rendered by the first loop.
templateB
{% for post in site.posts %}
{% unless same_condition %}
<!-- Render the post -->
{% endunless %}
{% endfor %}
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}} %}
I want to display keywords and description automatically according to the category of the current post. I've used the following code, but it doesn't worked.
{% if page.categories = "category" %}
{% else %}
{% endif %}
But while using {% page.categories %} it is echoing out the category name correctly. Here are my two doubts:
How can I compare the current post's category?
Are {{ }} and {% %} are same here?
It should look like the following:
{% if page.categories == 'some-name' %}
Hei I am in some-name category
{% else %}
No I am not in some-name category
{% endif %}
2.
No, {{ }} and {% %} are not the same. {{ }} is used for echoing stuff, while {% %} is used for logic expressions and arguments.