Skip to content

set default page title to its filename? #646

Answered by oscarotero
writeblankspace asked this question in Q&A
Discussion options

You must be logged in to vote

That's because title is not a string, but a function, so if you print it in your templates, it prints the function body (fn.toString()).
If you want to set default values, I recommend to use a preprocessor. For example:

site.preprocess([".html"], (pages) => {
  for (const page of pages) {
    page.data.title = page.data.basename;
  }
});

In your specific case, you can use the basename variable, that contains the filename after removing the extension. In the layout, you can do:

<h1>{{ title || basename }}</h1>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@writeblankspace
Comment options

Answer selected by writeblankspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants