I'm using docpad and on index page, in navigation pane I want to get a list of links grouped by category.
Category is defined in each markdown document in meta info on top. For example category:"tutorials"
So I have this:
<% for docu in #getFilesAtPath("document-repository").toJSON(): %>
<li><h2><%=cat=docu.category%></h2></li>
<%for docu in #getFilesAtPath("document-repository",category:cat}).toJSON():%>
<li><%=docu.title%></li>
<%end%>
<% end %>
But of course it is bad as it is looping as many times as many documents I have. I have only one category and I want it to loop only once when list of links is printed.
With jekyll it was done like this (part of _includes nav.html from https://github.com/devo-ps/carte) :
{% for category in site.categories %}
<li><h2>{{ category | first }}</h2>
<ul>
{% for posts in category %}
{% for post in posts %}
<li class='{{ post.type }}'><a href='#{{ post.url }}'>{{ post.title }}</a></li>
{% endfor %}
{% endfor %}
</ul>
</li>
{% endfor %}
He somehow knows how many categories are there. I don't know how to port it to docpad
I think the best question is when after asking in you find the answer :)
So I found a "workaround" at least I think it is a workaround and not a solution. For me that is perfect:
I've added "categories" to docpad.coffee file
templateData:
site:
categories: ['Tutorials','General']
Now I will always update this array with categories that should be used in meta info of each markdown doc
My loop looks like this now....and works!!!
<% for category in #site.categories : %>
<li><h2><%- category %></h2>
<ul>
<%for docu in #getFilesAtPath("document-repository",[{filename: -1}]).findAll({category:category}).toJSON():%>
<li><%=docu.title%></li>
<% end %>
</ul>
</li>
<% end %>
Related
Each time i autoindent (with alt+shift+f) my comments move to the right. Each time i autoindent, they go away more like they still need to be aline.
I'm using VSSCode and it's only when i'm on a twig file with twig comment {# (from what i aware of)
Here an exemple:
</li>
{# {% if not is_granted('IS_AUTHENTICATED_FULLY') //connexion admin caché
<li class="nav-item col-1">
<a class="nav-link" href="{{ path("app_login")}}">
connexion
</a>
</li>
<li class="nav-item col-1"> //pas de pages d'inscription pour mon site.
<a class="nav-link" href="{{ path("app_register")}}">inscription</a>
</li> #}
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
(i'm french so correct me if i make errors)
So i have tested each twig formatter and Prettier - Code format is the one working for me for the moment but i'm not satisfied: no control over how to format.
I don't know why there are so many twig formatter not working but "meh".
Problem
Recently I added tag support for my personal blog, but I am not happy with a way that it was done.
Blog uses jekyll with github-pages, so my solution has many limitations that platform comes with.
In order to create tag javascript I created file tag/javascript/index.html with following content:
---
layout: tag
tag: javascript
---
And it in my tag layout file I have following code:
---
layout: default
---
<div class="tag-header">
posts related to <strong>{{ page.tag }}</strong>
</div>
{% for post in site.posts %}
{% if post.tags contains page.tag %}
<section class="post">
<header>
{{ post.title }}
</header>
<time>
{{ post.date | date_to_string }}
</time>
<summary>
{% if post.excerpt %}
{{ post.excerpt }}
read more
{% endif %}
</summary>
<div class="tags">
{% for tag in post.tags %}
<span>
#{{ tag }}
</span>
{% endfor %}
</div>
</section>
{% endif %}
{% endfor %}
Result is something like this posts related to javascript.
Question
How can I automate tag creation process, so it does not require manual tag file creation (tag/javascript/index.html from sample)?
Notice
I have read An easy way to support tags in a jekyll blog already, and the only working solution for github-pages was this one, which I don't like, because it puts all tags in one page.
Additionally note that I am using github-pages, so custom plugin is not an option.
You can find full sources here.
Current Jekyll (3.1.x) cannot generate tag page automatically. You need to use a custom plugin. But you don't want to.
Why ? It's not so difficult to change deployment process on github pages.
You can store you code in master and you generated page in gh-pages. This answer will give your more information on how to do it.
I'm using jekyll to host a website on github.io
The homepage has a "Recent Posts" section which displays the latest 10 posts.
I'm using the following code in my index.html to generate the list:
<ul class="post-list">
{% for post in site.posts limit:10 %}
<li><article>{{ post.title }} <span class="entry-date"><time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%B %d, %Y" }}</time></span>{% if post.excerpt %} <span class="excerpt">{{ post.excerpt }}</span>{% endif %}</article></li>
{% endfor %}
</ul>
The _posts directory has 3 subdirectories. The above code generates a list from all three directories. I want to exclude the posts in one of those directories in my "Recent Posts" directory.
More generally, how can I select a subset of the subdirectories in the _posts directory?
I solved the problem by adding an if statement inside the for loop:
{% if post.path contains 'xxx' or post.path contains 'yyy'%}
<li><article>...</article></li>
{% endif %}
This works for simple cases but it could get ugly for more complicated cases.
The for loop seems to be iterating over a list but I can't figure out how to generate a list with the elements I want. I can't find a good reference for the scripting language used by Jekyll.
I am trying to retrieve the template for a specific product while NOT on the product template page. I am on the collection page and am trying to adjust the Quick shop feature to only show the add to cart for products no associated with a custom template. For example, I've assigned a 'consultation' template to a group of products. However because I am no longer on the product template page, the Quick shop doesn't recognize the consultation product. Any ideas on how I can make this work other than using tags, types and collections?
Thank you!!
On collection page , products for that collection are called in a loop, something like
{% for product in collection.products %}
...
{% assign prodtemplate = product.template_suffix %}
{% if prodtemplate contains 'consultation' %}
{% else %}
//Add to Cart code
{% endif %}
...
{% endfor %}
I'm new to jekyll and am working on building my site.
I have a "posts" layout where I'd like to have all the tags associated with the post appear in the left column. The problem I'm running into is that using {{ page.tags }} returns a list of tags that are not comma-separated and looks messy. See here for an example.
The html code for the layout page is:
<div class="span3">
</br>
<img src="{{ page.root }}assets/img/glyphicons_045_calendar.png" /> {{ page.date | > date: "%d %B %Y" }}
</br>
<img src="{{ page.root }}assets/img/glyphicons_066_tags.png" /> {{ page.tags }}
</div>
<div class="span9">
<h1> {{ page.title }} </h1>
{{ content }}
</div>
Any advice on how to (a) get the tags list to be comma-separated and (b) wrap around so it stays within the left column? Thanks!
You might try to put them inside a <p> tag so they can wrap around.
To have them comma-separated, you can follow the jekyll docs and use:
{{ page.tags | array_to_sentence_string }} => foo, bar, and baz
As is said in the Jekyll wiki.
For more precise control over what you can do with tags use the for operator:
<ul>
{% for tag in page.tags %}
<li> {{tag}} </li>
{% endfor %}
</ul>
This example is taken verbatim from somewhere. There are also more control structures to choose from.