jbake icon indicating copy to clipboard operation
jbake copied to clipboard

(Docs) Tags-index template input is not documented

Open OndraZizka opened this issue 6 years ago • 7 comments

I wanted to implement tags-index.ftl, but I didn't find a docs on what template variables are set: https://jbake.org/docs/2.6.1/#tags_index

I might add it later today.

Edit: I looked at the source code and I don't see anything being added. Where is the template author supposed to get the tags data?

	if (config.getBoolean(Keys.RENDER_TAGS_INDEX)) {
		try{
			// Add an index file at root folder of tags.
			// This will prevent directory listing and also provide an option to
			// display all tags page.
			Map<String, Object> model = new HashMap<String, Object>();
			model.put("renderer", renderingEngine);
			Map<String, Object> map = buildSimpleModel(Attributes.TAGS);
			map.put(Attributes.ROOTPATH, "../");
			model.put("content", map);

			File path = new File(destination.getPath() + File.separator + tagPath + File.separator + "index" + config.getString(Keys.OUTPUT_EXTENSION));
			render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex")));
			renderedCount++;
		} catch(Exception e){
			errors.add(e);
		}
	}

And...

private Map<String, Object> buildSimpleModel(String type) {
    Map<String, Object> content = new HashMap<String, Object>();
    content.put(Attributes.TYPE, type);
    content.put(Attributes.ROOTPATH, "");
    // add any more keys here that need to have a default value to prevent need to perform null check in templates
    return content;
}

OndraZizka avatar Jul 23 '18 09:07 OndraZizka

Take a look at default.properties Maybe we need something like jbake config to list all current configuration settings?

ancho avatar Jul 23 '18 11:07 ancho

+1 for jbake config

ottlinger avatar Jul 23 '18 12:07 ottlinger

Thanks. What exactly should I look at? I can see render.tags-index, but there is no template in the example site, and there is no documentation about what variables to use.

Maybe I overlooked something, but I had to add a few methods, and now I can use:

<#include "header.ftl">
	<#include "menu.ftl">
	<div class="page-header">
    	    <h1>Tags Index</h1>
	</div>

    <#list tagsMap>
    <ul>
    <#items as tagName, tagCount>
        <li><a href="${config.site_baseUrl}/${config.tag_path}/${tagName}.html">${tagName}</a> (${tagCount})</li>
    </#items>
    </ul>
    <#else>
        <p>No tags found.</p>
    </#list>

<#include "footer.ftl">

OndraZizka avatar Jul 23 '18 13:07 OndraZizka

It was just a pointer to all the properties jbake knows per default. The example repository for freemarker has no file called tags-index.ftl That's why you need to define your own template. But yes that is something worth mentioning in the docs. An index template should have access to the global data model.

ancho avatar Jul 23 '18 13:07 ancho

I see. Thanks! I missed the fact that tags is a TagModel, I thought its just set of strings. I'll try that.

OndraZizka avatar Jul 23 '18 15:07 OndraZizka

Ok, tried, works. I will make a PR to mention these model properties in https://jbake.org/docs/2.6.1/#tags_index , ok?

OndraZizka avatar Jul 23 '18 21:07 OndraZizka

Sounds good to me 👍

It may be time to re-work the Data Model section of the docs using a different presentation approach... not sure what yet myself... maybe the section needs more example snippets showing how each variable is used in a template engine.

jonbullock avatar Jul 31 '18 12:07 jonbullock