picocms / Pico

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

Question using {{ page.content }} #511

Closed DJoerger closed 4 years ago

DJoerger commented 4 years ago

Hello, i'm a beginner with not much coding knowledge (i know, best precondition ;) ) and try to setup Pico as a blog. Pico is up and running, everything works fine, except one thing:

I try to show the last blog posts with their content (not only description) on the front page and i thought {{ page.content }} would do the job...

My code looks like:

` {% for page in pages|sort_by("time")|reverse %} {% if page.id starts with "blog/" and not page.hidden %}

{{ page.title }}

{{ page.date_formatted }}

{{ page.content }}

    {% endif %}
    {% endfor %}`

And simply doesn't work. I can't find anything about this in the docs, so i hope someone can help me out.

With best regards Denis

PhrozenByte commented 4 years ago

Try Pico's conent Twig filter: {{ page.id|content }}

Also see Pico's user docs at http://picocms.org/docs/#themes:

To get the parsed contents of a page, pass its unique ID to the content filter (e.g. {{ "sub/page"|content }}).

DJoerger commented 4 years ago

Hi, thanks for your answer! I've tried {{ "blog/"|content }} before, but it didn't worked...

PhrozenByte commented 4 years ago

That's because blog/ is no page ID, the Twig filter expects a page ID (like sub/page or blog/my-first-article).

DJoerger commented 4 years ago

Ah, yes, but i want to show the content of the last five blog articles. Single page content is not what i'm searching for.

PhrozenByte commented 4 years ago

This has nothing to do with the content Twig filter, but with your loop; you simply have to iterate just the 5 pages you want to.

{% for page in pages|sort_by("time")|reverse if page.id starts with "blog/" and not page.hidden %}
    {% if loop.index <= 5 %}
        <div class="post">
            <h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
            <p class="date">{{ page.date_formatted }}</p>
            <p class="entry">{{ page.id|content }}</p>
        </div>
    {% endif %}
{% endfor %}
DJoerger commented 4 years ago

Many thanks, now i've got it! :)

Nest step: have a look how good Pico performs with a few hundred blog entries. ^^

stale[bot] commented 4 years ago

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! :+1: