set default page title to its filename? #646
-
export const layout = "layouts/blogPage.vto";
export const category = "blog";
export const title = (page: any) => {
return page.data.filename;
}; I tried this in Am I doing this wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's because site.preprocess([".html"], (pages) => {
for (const page of pages) {
page.data.title = page.data.basename;
}
}); In your specific case, you can use the <h1>{{ title || basename }}</h1> |
Beta Was this translation helpful? Give feedback.
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:
In your specific case, you can use the
basename
variable, that contains the filename after removing the extension. In the layout, you can do: