picocms / Pico

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

Breadcrumbs #641

Closed ctuxboy closed 2 years ago

ctuxboy commented 2 years ago

Trying develop a breadcrumb snippet:

      {%- if current_page.id == '/' -%}
        This is the homepage
      {%- else -%}
        <a href="{{ base_url }}">home</a>/<a href="{{ meta.url }}">{{ meta.title }}</a>
      {%- endif -%}

This doesn't work, so what i try to do:

The most md-files have the meta attribute template. The templates are province, city and dogzone. Is there a way build an if-statement like this:

{%- if {{ page.meta.template }} == 'province' -%}
...
{%- elseif {{ page.meta.template }} == 'city' -%}
...
{%- elseif {{ page.meta.template }} == 'dogzone' -%}
...
{%- endif -%}

Or is it possible check the twig template files:

Hope someone can give me a hint?

ctuxboy commented 2 years ago

Okay,

I found this, it is not page.meta.template, but meta.template :see_no_evil:

Okay but how test, if it is the homepage? Try this, but doesn't work:

{%- if current_page.id == '/' -%}
...
{%- endif -%}
ctuxboy commented 2 years ago

Found it!

{%- if is_front_page -%}
  This is the homepage
{%- elseif {{ meta.template }} == 'city' -%}
...
{%- endif %}
mayamcdougall commented 2 years ago

Hey there. 👋🏻

Sorry, getting behind on things again. 😅

So, is_front_page is actually depreciated. This is why it isn't mentioned in the Docs. It's from Pico 1.0 and earlier.

If I had to guess, you're probably not using a pico-theme.yml file in your Theme, which means the Pico Deprecated plugin is giving you access to old stuff like is_front_page (it's assuming your Theme is very old).

The proper way to do this is like your earlier example, except the page id isn't /, it's index.

{% if current_page.id == "index" %}
...
{% endif %}

Though, if is_front_page is more readable for you (or more convenient, if you're using it frequently), there's no reason you couldn't define it yourself.

{% if current_page.id == "index" %}
  {% set is_front_page = true %}
{% endif %}
ctuxboy commented 2 years ago

Hey there. 👋🏻

Sorry, getting behind on things again. 😅

So, is_front_page is actually depreciated. This is why it isn't mentioned in the Docs. It's from Pico 1.0 and earlier.

If I had to guess, you're probably not using a pico-theme.yml file in your Theme, which means the Pico Deprecated plugin is giving you access to old stuff like is_front_page (it's assuming your Theme is very old).

The proper way to do this is like your earlier example, except the page id isn't /, it's index.

{% if current_page.id == "index" %}
...
{% endif %}

Though, if is_front_page is more readable for you (or more convenient, if you're using it frequently), there's no reason you couldn't define it yourself.

{% if current_page.id == "index" %}
  This is the homepage
{% endif %}

No problem @mayamcdougall , i'm happy you or other member(s) answers within a few days :smiley:

hmm, very strange, there is a pico-theme.yml exist. Screenshot 2022-06-15 21 01 52

Change my code and works like a sharm :heart_eyes:

{%- if current_page.id == "index" -%}
      This is the homepage
{%- elseif meta.template == 'city' -%}
...

Where can i found all the attributes and functions in Pico? Not all this stuff is documented in the docs. I found is_front_page in one of the available pico theme's.

mayamcdougall commented 2 years ago

hmm, very strange, there is a pico-theme.yml exist.

I'm not sure then. I'm not an expert at Pico's inner workings. 😅

The is_front_page variable is definitely deprecated though. You can see it in the changelog. It was introduced in Pico 0.5, and removed in 2.0.

So, I'm not sure what is triggering it, but it's definitely only being provided by pico-deprecated, and isn't something you should use in modern code. (@PhrozenByte, is this accurate? Are there other situations that could result in pico-deprecated being activated?)

Actually, come to think of it, I think you were using some older plugins, right? I'm not sure if the compatibility modes for Themes and Plugins are triggered separately, so it's possible that those might be what's causing pico-deprecated to run.

Other than a lack of documentation around pico-theme.yml, I'm not sure as there's anything outright missing from the Docs. The main issue is that the Docs are very information dense and often explained somewhat poorly.

All of the "attributes and functions" you're looking for are listed under the Customizations > Themes section that you've seen before. If there's something you saw in another Theme that you can't find in the Docs, it was probably either removed from Pico a long time ago (like is_front_page) or maybe it was being provided by a plugin.

And, I know I've linked them before, but the Twig Docs are also really handy for looking up all of Twig's functions. I tend to use them more than Pico's Docs, as usually when I'm coding a theme, it's Twig functions I need to search through (and/or remember how to use 😅 ), not Pico-specific ones.

Finally, if you're interested, you can view my Work-in-Progress Docs Rewrite*, which attempts to simplify things and break topics into their own pages. Theming with Twig would be the page to look at, though other than the revised content, the lists of Pico-specific variables will be largely the same as what's already in the Docs.

(* Not a permalink, as sometimes I need to point GitHub Pages to a different branch, depending on what I'm working on.)

(And any feedback you want to give on that project is appreciated. Maybe someday I'll even finish it. 😅😒)

PhrozenByte commented 2 years ago

So, I'm not sure what is triggering it, but it's definitely only being provided by pico-deprecated, and isn't something you should use in modern code. (@PhrozenByte, is this accurate? Are there other situations that could result in pico-deprecated being activated?)

Old plugins also trigger the deprecated theme features, because plugins might also include Twig templates.

I'm a bit ambivalent about PicoDeprecated in general, because it doesn't create any real reason to actually upgrade stuff. On the other hand we have a pretty limited number of 3rd-party plugins and themes, a lot of them unmaintained, so dropping more features more frequently is a likely a bad idea, too. So, in the end it's a trade-off...

ctuxboy commented 2 years ago

@PhrozenByte @mayamcdougall , Indeed there is a older plugin installed (Pico Editor) so this can be the reason :smiley:

Hi thanks for the info, this link is really useful and help me a lot, also the Twig docs are very handy :smiley:

mayamcdougall commented 2 years ago

@PhrozenByte Maybe PicoDeprecated should be optional? Either a separate download or require it to be manually enabled?

In a perfect world, that would probably help, but unfortunately, I don't think there's enough active developers for that to actually "incentivize" any updates. It'd only be inconveniencing users. 😔

If we did want to force this change though... 3.0 would technically be a good time to do it, since theme compatibility is already breaking. 😓

Hi thanks for the info, this link is really useful and help me a lot, also the Twig docs are very handy 😃

No problem. 😉

Glad you like the rewrite. If I could just get around to finishing the rest of it, maybe we could update the website with it, lol. 😅

And yeah, the Twig Docs are great. I plan to mention them more in the rewritten docs, because they really are the best place to learn everything you'd ever need to know about Twig.

It's funny because, if you ask me, there's more to learn about Twig than Pico. Once you've mastered it, you can really make just about anything you'd ever want in Pico. 😁

ctuxboy commented 2 years ago

It's funny because, if you ask me, there's more to learn about Twig than Pico. Once you've mastered it, you can really make just about anything you'd ever want in Pico.

I know, but sometimes there are specific Pico variables(?), so the Pico doc pages can help devs a lot.

I'm starting my own picocms-notes.

mayamcdougall commented 2 years ago

I know, but sometimes there are specific Pico variables

I mean, there's pages, and knowing how to navigate its contents (page content, metadata, etc). But other than the few tidbits you see in the section I linked (the meta properties and the few Pico-specific filters), there really isn't anything else.

It's more about knowing how to leverage that data, like with the snippets you're collecting. 😉

In the end, I would like to provide more snippets like those in the Docs rewrite. I plan to have a dedicated page for them. Just some nice, free, building blocks to get people started with things that go deeper than what the Default Theme shows.