Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help ! Completely lost for theming with categories #438

Closed
bricebou opened this issue Jun 23, 2018 · 21 comments
Closed

Help ! Completely lost for theming with categories #438

bricebou opened this issue Jun 23, 2018 · 21 comments

Comments

@bricebou
Copy link

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:

  • root/supcategory/index.md

/*
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
*/

  • root/supcategory/category/page.md

/*
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 #412 and #414 but I can't make anything work :-(

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

Here are some questions:

  • in my first level (supcategory), how can I list all the categories (separate folders with index.md within) ?
  • how can I list all pages in categories ?

Thanks in advance !

@PhrozenByte
Copy link
Collaborator

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
Copy link
Author

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 #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
Copy link
Author

So, I'm trying to use in my category.twig template the current_page.tree_node.children mentioned in #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
Copy link
Collaborator

PhrozenByte commented Jun 23, 2018

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
Copy link
Author

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
Copy link
Collaborator

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

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

@bricebou
Copy link
Author

bricebou commented Jun 23, 2018

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
Copy link
Collaborator

PhrozenByte commented Jun 23, 2018

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
Copy link
Author

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
Copy link
Collaborator

PhrozenByte commented Jun 24, 2018

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
Copy link
Author

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:

  • it seems that meta in the meta are "lowercased"... in my md files, Category: test is accessible with page.meta["category"] but isn't with page.meta["Category"]
  • I'm surprised to see that the template variable is no longer available simply with page.template but needs to be called with `page.meta["template"]. Here again, the initial capital is left aside.

Thanks again !

@PhrozenByte
Copy link
Collaborator

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

@bricebou
Copy link
Author

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
Copy link
Collaborator

Yes, that's because this is no Pico 2.0 installation 😉 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
Copy link
Author

Hum... I don't understand...
I've used git clone [email protected]:picocms/Pico.git and run composer install... what have I done wrong ?

@PhrozenByte
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

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

DummyPlugin.enabled: false

@bricebou
Copy link
Author

Sorry ! too fast reading

@bricebou
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants