picocms / Pico

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

Reverse case sensitive declaration of meta attributes is confusing #684

Closed dipohl closed 6 months ago

dipohl commented 6 months ago

I tried to declare my 'lang' attribute in the pico-theme.yml and found that I had to use lower case 'lang' in the declaration:

meta: # Register meta headers used by this theme lang: de # Used to filter by language

and upper case in the twig files:

{{ page.meta.Lang }}

to use the existing upper case declarations from the pages content header:

Lang: de

Other combinations didn't work.

Why is that so? And can it be changed so that it is at least consistent? The best for Usability would be case insensitive at least in the content area.

fyi & kind regards

PhrozenByte commented 6 months ago

In pico-theme.yml you declare known meta headers like in Pico's onMetaHeaders event, i.e. search_string: replace_string. In your case you want Lang: lang there, i.e. a Lang meta header is saved as lang, so that you can access it via lowercase.

dipohl commented 6 months ago

Thanks for the explanation. When I searched for docs about the meta headers I found your source code documentation :-) https://picocms.org/phpDoc/pico-3.0/classes/DummyPlugin.html#method_onMetaHeaders The global doc index page says for this branch "Last Update: 2021-03-23 22:22" Can you please trigger a next generation?

Back to this issue here: a sentence of instruction in the pico-theme.yml would be good to have. At the time I see there:

meta: # Register meta headers used by this theme Logo: logo # The URL to your website's logo (value is passed to Pico's "url" Twig filter) Tagline: tagline # Your website's tag line, shown right below your site title (supports Markdown) Social: social # A list of social icons that will be shown in your website's footer;

You must specify a "title", "url" and "icon" per entry

I propose to add there something like this:

meta: # Register meta headers used by this theme

You may add further meta headers for your theme.

                                 # The string on the left side shall be used in the content headers to set a value for the page.
                                 # Access the value in your themes twig files via the string on the right side i.e. {{ page.meta.tagline }}
dipohl commented 6 months ago

Found a new issue concerning the meta headers. Your recipe works for the index twig files. There the access via {{ page.meta.lang }} works within a loop over % for page in pages("blog")|sort_by("time")|reverse %}

But for a single page view (without the loop), this delivers no value. It works there when I access via {{ meta.lang }}

What is needed in the page view twig file, so that I can use the same syntax in all twig files?

PhrozenByte commented 6 months ago

I propose to add there something like this:

Pull request is welcome :+1:

What is needed in the page view twig file, so that I can use the same syntax in all twig files?

I don't really understand the question. They are different things after all? One is the current page, the other is an iteration through all pages, thus a whole different story and used in a different context for different things.

dipohl commented 6 months ago

I propose to add there something like this:

Pull request is welcome 👍

ok, I'll do

What is needed in the page view twig file, so that I can use the same syntax in all twig files?

I don't really understand the question. They are different things after all? One is the current page, the other is an iteration through all pages, thus a whole different story and used in a different context for different things.

ah, I see. The created field is called meta.lang and only because the loops cursor is called 'page' I have to set its name before meta.lang, right?

hmm, was a stupid question then and shows my state of confusion at the time (see the subject of this issue report ;-)