picocms / Pico

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

Help ! Completely lost for theming with categories #438

Closed bricebou closed 6 years ago

bricebou commented 6 years ago

Hi,

It's been a while but I'm trying to move from version 1 to the latest Pico's development.

But I can't make my theme working :-(

I have a three levels folder system:

/ Title: Mon parcours Author: Brice Boucard License: Creative Commons Attribution-ShareAlike 4.0 International License category: true Template: supcategory /

  • root/supcategory/category/index.md

/ Title: Maîtrise Sciences du langage Author: Brice Boucard License: Creative Commons Attribution-ShareAlike 4.0 International License category: true Template: category parent: Mon parcours /

/ Title: Discours : la vulgarisation scientifique Description: Dossier sur le discours de vulgarisation scientifique, à partir d'un corpus de trois articles du Monde. Author: Brice Boucard Date: 2006/10/03 License: Creative Commons Attribution-ShareAlike 4.0 International License Tags: études,linguistique,discours parent: Maîtrise Sciences du langage Template: index /

I've read https://github.com/picocms/Pico/issues/412 and https://github.com/picocms/Pico/issues/414 but I can't make anything work :-(

My old theme is here and https://github.com/bricebou/pico_momh

Here are some questions:

Thanks in advance !

PhrozenByte commented 6 years ago

There were some breaking changes in Pico 2.0 towards theming. Please refer to the current WIP version of Pico's upgrade docs at http://phrozenbyte.github.io/Pico/in-depth/upgrade-pico-20/ to see what has changed and how to make your theme compatible with Pico 2.0.

Furthermore it seems that you're using the category meta wrong? In category.html there's L14 and L17, so you're comparing a page title (meta.title) with a boolean (category: true in your YAML Front Matter)?

bricebou commented 6 years ago

It's because it's the previous version of the code but I've changed my yaml content header because thought the "category" meta was from the core based on https://github.com/picocms/Pico/issues/414... :-/

Initially, here what a supcategory index.md:

/ Title: Mon parcours Author: Brice Boucard License: Creative Commons Attribution-ShareAlike 4.0 International License Template: supcategory /

And here is the category meta index.md:

/ Title: Maîtrise Sciences du langage Author: Brice Boucard License: Creative Commons Attribution-ShareAlike 4.0 International License Template: category Category: Mon parcours /

My theme on v1 renders that : http://momh.fr/parcours/M1 But, with v2, it doesn't show anything but the title.

bricebou commented 6 years ago

So, I'm trying to use in my category.twig template the current_page.tree_node.children mentioned in https://github.com/picocms/Pico/issues/414 but it seems it's "empty"... {% for item in current_page.tree_node.children %} {{ item.category }} - {{ item.title }} <br> {{ meta["Category"] }} <br> {% endfor %}

PhrozenByte commented 6 years ago

You are not required to use Pico's new page tree system if you had a working solution before. Your old solution should work with Pico 2.0 without any changes necessary. #414 is a completely different approach, you can't mix this solution with your solution.

If you really want to use Pico's page tree system, refer to the current WIP version of Pico's page tree documentation. The tree_node.children array is not a list of pages, but a list of tree nodes. You're rather looking for item.page.meta.category - but note that item.page doesn't necessarily exist (see the docs).

bricebou commented 6 years ago

The thing is: what worked doesn't work anymore...

I was using the AdvancedMeta plugin and declared some meta this way:

$config['custom_meta_values'] = array(
    //page category
    'category' => 'Category',
    //page status
    'license' => 'License',
    'thumbnail' => 'Thumbnail'
);
PhrozenByte commented 6 years ago

Unfortunately I can't help you if you just give me "it doesn't work anymore" :wink:

The plugin with this config shouldn't make any difference here.

bricebou commented 6 years ago

Of course :-)

It was more kind of a question: do I have to keep with the version 2 of Pico the AdvancedMeta plugin, or is there a way to let it aside ? I thought it was no longer necessary... and I thought you didn't have to declare custom meta...

But, of course, I wasn't clear --"

Thanks :-)))

PhrozenByte commented 6 years ago

There were some changes regarding the handling of meta headers that weren't registered by a plugin. See the 5th paragraph of http://phrozenbyte.github.io/Pico/in-depth/upgrade-pico-20/#amazing-new-features-for-theme-developers. You should access the meta value "Category" using meta["Category"] (note the uppercase C, i.e. case matters now).

The AdvancedMeta plugin never really was necessary. Its existance is a sign that Pico's handling of meta headers was a bit confusing in the past. That's one of the the reason why we no longer do unexpected things and simply pass unregistered meta headers through without change.

Theme developers don't have to register meta values. You just have to make sure that you use the exact same keys, i.e. if your theme uses {{ meta["category"] }}, use category: My category in your YAML Front Matter. If your theme rather uses {{ meta["Category"] }}, use Category: My category in your YAML Front Matter (note the uppercase C).

bricebou commented 6 years ago

Ok...

But in my category.twig template, I have this:

{% for page in pages %}
    {% if page.meta["Category"] is sameas(cate) and page.template != 'category' %}
        <li>
            <a href="{{ page.url }}">
                <time class="vtl_date meta" datetime="{{ page.date }}" ><span>{{ page.date|date("d/m/Y", "Europe/Paris")}}</span></time>
                <div class="vtl_point"><i class="fa"></i></div>
                <div class="vtl_label">
                    {{ page.title }}
                </div>
            </a>
        </li>
    {% endif %}
{% endfor %}

Of course, it doesn't produce any result. If I try to replace page.category with page.meta["Category"], it doesn't produce anything...

Any idea ? Thanks :-)

PhrozenByte commented 6 years ago

Try debugging which values the variables page.meta["Category"], page.meta["category"] and cate actually hold. Enalbe Twig's debug mode by adding twig_config: { debug: true } to your config/config.yml and add {{ dump(page.meta["Category"], page.meta["category"], cate) }} (after for, before if) to your Twig template.

bricebou commented 6 years ago

Thanks !

It seems that the trim Twig filter is a part of the solution: using {% set cate = meta.title|trim %} and then if page.meta["category"]|trim is sameas(cate) renders some results.

But:

Thanks again !

PhrozenByte commented 6 years ago

What does {{ dump(current_page, version) }} output? (outside the for loop)

bricebou commented 6 years ago

Here it is:

array(11) { ["id"]=> string(17) "parcours/M1/index" ["url"]=> string(38) "http://dev.localhost/parcours/M1/index" ["title"]=> &string(29) "Maîtrise Sciences du langage" ["description"]=> &string(0) "" ["author"]=> &string(13) "Brice Boucard" ["time"]=> &string(0) "" ["date"]=> &string(0) "" ["date_formatted"]=> &string(0) "" ["raw_content"]=> &string(181) "/* Title: Maîtrise Sciences du langage Author: Brice Boucard License: Creative Commons Attribution-ShareAlike 4.0 International License Template: category Category: Mon parcours */" ["meta"]=> &array(10) { ["title"]=> &string(29) "Maîtrise Sciences du langage" ["author"]=> &string(13) "Brice Boucard" ["license"]=> string(65) "Creative Commons Attribution-ShareAlike 4.0 International License" ["template"]=> string(8) "category" ["category"]=> string(12) "Mon parcours" ["description"]=> &string(0) "" ["date"]=> &string(0) "" ["robots"]=> string(0) "" ["date_formatted"]=> &string(0) "" ["time"]=> &string(0) "" } ["content"]=> &string(0) "" } NULL 

It seems that the version doesn't show anything, isn't it ?

PhrozenByte commented 6 years ago

Yes, that's because this is no Pico 2.0 installation :wink: You said that you were trying to "move from version 1 to the latest Pico's development", but you're still using Pico 1.0. You can download the latest beta of Pico 2.0 here: https://github.com/picocms/Pico/releases

bricebou commented 6 years ago

Hum... I don't understand... I've used git clone git@github.com:picocms/Pico.git and run composer install... what have I done wrong ?

PhrozenByte commented 6 years ago

You've cloned the master branch, that is always the current stable release branch. Until Pico 2.0 is released, Pico 2.0 is found in the pico-1.1 branch (development startet as Pico 1.1 and was later renamed to Pico 2.0). This is explained in Pico's CONTRIBUTING.md. Anyway, you shouldn't use Git branches for a productive website anyway, but rather the latest release.

You can download the latest beta of Pico 2.0 here: https://github.com/picocms/Pico/releases. Pico's pre-bundled release is basically just a Composer installation packed in a ZIP archive. There's virtually no difference between a pre-bundled release and a Composer installation, both use picocms/pico-composer as a basis (however, you can't use picocms/pico-composer directly without changing Composer's minimum-stability until Pico 2.0 is released, thus I'd recommend to simply use the pre-bundled release, composer works with pre-bundled releases, too).

bricebou commented 6 years ago

Hum... --' Sorry...

So, I'm now running the latest beta of version 2. But I still see a problem with no-case sensitive meta.

in my twig category template:

{{ page.template }} -- {{ page.meta["template"]}} -- {{ page.meta["Template"] }} <br>
{{page.category }} -- {{ page.meta["category"]}} -- {{ page.meta["Category"] }}

And here the result:

-- index --
-- Master professionnel Édition -- Master professionnel Édition 

And here is the meta header of my content file:

/*
Title: Histoire de l'édition : la censure en France...
Description: Dossier d'histoire de l'édition : la censure en France... de la censure « officielle » à la « censure invisible »
Author: Brice Boucard
Date: 2009/07/02
License: Creative Commons Attribution-ShareAlike 4.0 International License
Tags: études,édition
Category: Master professionnel Édition
Template: index
*/

I can't give you the result of the dump command you gave earlier because of a memory limit (small and slow computer and memory limit fixed in php.ini fixed at 256 MB)...

PhrozenByte commented 6 years ago

That's how it is supposed to work.

Template is a registered meta header that intentionally changes the meta header's key. That's the reason why it is only accessible using {{ page.meta["template"] }}. Just refer to Pico's onMetaHeaders event.

The reason why you can access the unregistered meta header Category using both {{ page.meta["category"] }} and {{ page.meta["Category"] }} is explained in http://phrozenbyte.github.io/Pico/in-depth/upgrade-pico-20/: {{ page.meta["Category"] }} is the correct one for Pico 2.0, but PicoDeprecated preserves BC by making the meta value also accessible using {{ page.meta["category"] }}. You can disable PicoDeprecated by adding PicoDeprecated.enabled: false to your config/config.yml.

bricebou commented 6 years ago

I have this parameter set on default in my config.yml:

DummyPlugin.enabled: false
bricebou commented 6 years ago

Sorry ! too fast reading

bricebou commented 6 years ago

Made it working ! ... --' Thanks again :)