Log in Sign up

Posts with no title

For some of my entries I want to have a title, for some of them I would prefer not to have one. I modified the Blog template with

{{#title}} <h1>{{title}}</h1>{{/title}}

and I thought that would solve my problem. I.e. if the post didn't have a title then there would be no title shown, but Blot uses the file name as a title if there is not title in the frontmatter. I tried having an empty title, i.e.

title:

but then the title became “null”. Is it possible to have some entries to have no title?

5 replies

I've been playing around with this and looked at the JSON output. What seem to work is to use

{{#metadata.title}} <h1>{{title}}</h1>{{/metadata.title}}

Answered 6 months ago · Improve this answer

I realized that it would be useful for me to be able to define metadata that represents true/false. However, when I enter something like this

meta1: false

meta2: yes

both meta1 and meta2 is represented as strings. Is it possible to define metadata that have a bool value?

Or am I approaching this in the wrong way. When I try out what I want to to do in the mustache demo page everything is working the way I want but there I'm able to define bool values in the JSON file.

Answered 6 months ago · Improve this answer

It's not possible to define metadata with a bool, but an empty string or the non-existence of metadata will be 'false' as far as mustache is concerned, e.g. if you add this to only one entry, leaving it out of the others:

meta1: yes

And then do this in your template:

{{^metadata.meta1}}
... will show on the one entry
{{/metadata.meta1}}

{{^metadata.meta1}}
... will show on the others
{{/metadata.meta1}}

In terms of answering your question, I'd consider avoiding setting title metadata in any of your posts, instead using a title tag when you want the title to appear, like so:

# Title here

... post here

And then in your template, take advantage of the {{titleTag}} template tag like so, removing any uses of {{metadata.title}} or {{title}}:

{{{titleTag}}}
{{{body}}}

The result should be what you're after! Please let me know if you have any questions

Answered 6 months ago · Improve this answer

Thanks, I'll play around a bit more and then decide how to handle things

Answered 6 months ago · Improve this answer

Sounds good – feel free to email me with a link to your site and I'll be able to advise you on the specifics

Answered 6 months ago · Improve this answer

Markdown allowed
Question or feedback?
Contact us

Tags

developers 83 questions bug 40 questions posts 26 questions metadata 24 questions resolved 24 questions templates 23 questions how 14 questions tags 13 questions markdown 11 questions pages 9 questions More tags →
Subscribe for changes
RSS Feed of latest questions