picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Displaying only the body of the content #653

Closed notakoder closed 1 year ago

notakoder commented 1 year ago

I wish to display some page information after the heading, such as—

Title of the article Author name | Date | Tags Photo Body of article

But designing this using the twig template seems impossible because the {{ content }} variable also includes the heading of the page. So a template with the following snippet duplicates the heading.

{{ page.title }}
{{ meta.author | meta.data  | meta.tags }}
{{ meta.image }}
{{ content }}

I sure can achieve the required design using %variable_name% variables in the text file and duplicate the code with in markdown file, but this doesn't seem the most appropriate way to achieve this. Is there any variable that only takes the content of a page minus the heading (or title). If not, what is the workaround to achieve such a design?

PhrozenByte commented 1 year ago

Just remove the header from the Markdown contents.

notakoder commented 1 year ago

I am sure I have misunderstood your comment.

If I remove the header from the markdown files, the template can no longer get the meta details such as author, date, etc... Moreover at least the Template: header must be present there to be rendered correctly.

PhrozenByte commented 1 year ago

I presume your Markdown file currently looks like the following:

---
title: The title of my page
date: 2022-12-09
---

# The title of my page

This is the content of my page

This will result in having a duplicate title. Just remove the Markdown title:

---
title: The title of my page
date: 2022-12-09
---

This is the content of my page
notakoder commented 1 year ago

I did this before but I never liked the incompleteness of the markdown file—it looked like it doesn't have a head. Beyond the aesthetic part, this also strips the semantic of the markdown—a document without an h1.

But, it seems like this is the only workaround for the requirement. Thanks anyway.

notakoder commented 1 year ago

Just a quick question. Why is the code <p>Written by {{ meta.author }}</p> in the twig template not show the white space between "by" and the author's name? It should be: Written by Jane Doe. But it shows: Written byJane Doe

notakoder commented 1 year ago

This can be resolved by adding &#32;, but I am quite curious why a normal space does not work.

mayamcdougall commented 1 year ago

@notakoder I've also been bitten a fair amount by this space removal, especially on older themes (including my own work).

I believe at some point, Twig slightly changed the way it handled whitespace on either side of a Twig tag {{ }}, as this didn't use to happen. I usually just get around it with an &nbsp;.

I'd also be curious for a real answer on it, but I just wanted to let you know you weren't alone there. 😉

notakoder commented 1 year ago

I just wanted to let you know you weren't alone there.

Good to know that. :smile: But I prefer &#32; instead of a non-breaking space. That seem to be exactly what I want: a normal space.

mayamcdougall commented 1 year ago

But I prefer instead of a non-breaking space.

Definitely. I wasn't trying to say &nbsp; was better... its character code is just ingrained in my head from the early days of web design. 😅

notakoder commented 1 year ago

:+1: