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

How do I show folders or categories with Twig? #414

Closed
iagovar opened this issue Feb 5, 2018 · 9 comments
Closed

How do I show folders or categories with Twig? #414

iagovar opened this issue Feb 5, 2018 · 9 comments

Comments

@iagovar
Copy link

iagovar commented Feb 5, 2018

Hi all. I'm looking for a way to show in the index page the folders inside /content.

Basically I'm trying to recreate a SILO structure in my site, so the index page shows the categories of the site and a list of links where template: page. When the user clicks that categories another page shows listing all the documents inside such category.

I've looked in the picocms docs but I didn't find anything suitable, and reading twig documentation I'm a bit lost to be honest.

@PhrozenByte
Copy link
Collaborator

PhrozenByte commented Feb 5, 2018

This is a task predestined for the page tree shipped with Pico 2.0. You can download the latest beta from https://github.com/picocms/Pico/releases (also see #401). Don't worry about Pico 2.0 being in beta, it's actually ready-to-release, we just haven't finished the docs/website updates yet.

First create a index.md in all folders representing categories and add a YAML header (e.g. content/my_category/index.md):

---
title: My category
category: true
template: category
---

Listing categories (your index.twig):

<ul>
    {% for category in pages["index"].tree_node.children %}
        {% if category.page and category.page.meta.category %}
            <li><a href="{{ category.page.url }}">{{ category.page.title }}</a></li>
        {% endif %}
    {% endfor %}
</ul>

Listing pages in a category (your category.twig):

{% if meta.category and current_page.tree_node.children %}
    {% for child in current_page.tree_node.children %}
        {% if child.page and not child.page.hidden %}
            <div>
                <h3><a href="{{ child.page.url }}">{{ child.page.title }}</a></h3>
                <p>{{ child.page.description }}</p>
            </div>
        {% endif %}
    {% endfor %}
{% endif %}

#edit: Splitting templates.

@iagovar
Copy link
Author

iagovar commented Feb 5, 2018

Thank you, I'll download the 2.0 version and tell you if it worked.

@iagovar
Copy link
Author

iagovar commented Feb 6, 2018

It worked! Now I have another question. I want to put a PHP include inside a .md file. but it seems to output in plain text. Is there any way to scape the markdown interpreter for a few lines or any other way to do something similar?

@PhrozenByte
Copy link
Collaborator

This is not possible (on purpose). Use a Twig template instead (e.g. add Template: special_page to the YAML header of content/special_page.md and create a themes/my_theme/special_page.twig). If Twig really isn't sufficient, you'll have to create a Pico plugin instead (refer to the plugins section in the user docs, the (unfinished, help is highly appreciated) dev docs at http://picocms.org/development/ and Pico's DummyPlugin).

@iagovar
Copy link
Author

iagovar commented Feb 6, 2018

Well, if someone has the same problem, I'm doing it throug jquery:

`<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script> $(function(){ $("#tabla-webs").load("path/tabla-webs.html"); }); </script> `

<div id="tabla-webs"></div>

@iagovar
Copy link
Author

iagovar commented Feb 7, 2018

@PhrozenByte what if I change the documents format from .md to .html in the config file? Will that allow me to use php include?

@PhrozenByte
Copy link
Collaborator

No

@iagovar
Copy link
Author

iagovar commented Feb 7, 2018

:(

@stale
Copy link

stale bot commented Feb 14, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! 👍

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