Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alltags contains Strings instead of tag-maps #468

Closed
38leinaD opened this issue May 30, 2018 · 3 comments
Closed

alltags contains Strings instead of tag-maps #468

38leinaD opened this issue May 30, 2018 · 3 comments
Assignees

Comments

@38leinaD
Copy link

I would like to print a tag-index and using freemaker. The tag-index should print the number of posts per tag. I am doing it like this:

<#include "header.ftl">

	<#include "menu.ftl">
	
	<div class="page-header">
		<h1>Tags</h1>
	</div>
	
	<ul>
		<#list alltags as tag>
			<li><a href="${tag.name}.html">${tag}</a> (${tag.tagged_posts?size})</li> <!-- THIS IS LINE 11 -->
		</#list>
	</ul>
	
<#include "footer.ftl">

I get the following error:

Failed to render tagindex

	at org.jbake.launcher.Baker.bake(Baker.java:32)
	at org.jbake.launcher.Main.run(Main.java:97)
	at org.jbake.launcher.Main.run(Main.java:82)
	at org.jbake.launcher.Main.main(Main.java:36)
Caused by: org.jbake.template.RenderingException: java.lang.Exception: Failed to render tags. Cause(s):
Failed to render tagindex
	at org.jbake.render.TagsRenderer.render(TagsRenderer.java:20)
	at org.jbake.app.Oven.bake(Oven.java:155)
	at org.jbake.launcher.Baker.bake(Baker.java:20)
	... 3 more
Caused by: java.lang.Exception: Failed to render tags. Cause(s):
Failed to render tagindex
	at org.jbake.app.Renderer.renderTags(Renderer.java:386)
	at org.jbake.render.TagsRenderer.render(TagsRenderer.java:18)
	... 5 more
Caused by: java.lang.Exception: Failed to render tagindex
	at org.jbake.app.Renderer.render(Renderer.java:239)
	at org.jbake.app.Renderer.renderTags(Renderer.java:373)
	... 6 more
Caused by: org.jbake.template.RenderingException: freemarker.core.NonHashException: For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> atag  [in template "tags-index.ftl" at line 11, column 40]

I am neither an expert on jbake nore freemaker but based on the jbake documentation that states that

alltags = collection of all tags used across all published content

and that

Global variable tags represent a collection of all tags. Each tag in this collection is represented by a map containing following attributes -

Expected:
I assumed that alltags would also give a map instead of tag-maps.

Actual:
alltags just contains a list of tag-strings

Is there a workaround? I.e. What is a way to get the posts for a tag? Or more specific the number of posts per tag?

@jonbullock
Copy link
Member

This Freemarker code snippet will give you a list of tags and the number of posts for each tag:

	<ul>
		<#list tags as tag>
			<li><a href="${tag.uri}">${tag.name}</a> (${tag.tagged_posts?size})</li>
		</#list>
	</ul>

@38leinaD
Copy link
Author

now i am feeling stupid. i did not read the documentation carefully. thanks for point out the obvious. 👍

@jonbullock
Copy link
Member

I wrote that section and even I had to double check the code after reading it again.

Documentation can always be improved and this is one example, a code snippet under that section would help immensely. I'll raise an issue on the web site to make sure it's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants