PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

[Question] phileFolderLoop plugin: Passing a twig variable as loop argument #108

Closed lasbian closed 10 years ago

lasbian commented 10 years ago

Hi there,

Just started Philing. As the title states i'm hoping to pass a twig variable to the phileFolderLoop plugin, letting the loop walk over images in every page within the page 'for-loop'. Two issues i have:

a) The phileFolderLoop plugin does not handle twig variables. Can this be handled?

b) Obviously the {{ page.path }} is pseudo-code, since .path is not a phile-callback such as page.url. How do i get around this?

If working this would be an ideal scenario:

    {% for page in pages %}
        {% set images = loop({{ page.path }}) %}
        {% for image in images %}
            <div class="col-1-2">
            <a href="{{ image.url }}" data-count="{{ image.id }}" target="_blank">
            <img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.name }}">
            </a>
            </div>
        {% endfor %}
    {% endfor %}

I hope you get my problem :)

Lasbian

james2doyle commented 10 years ago

You can create custom meta in Phile which you couldn't do by default in Pico. You access it with {{ page.meta.custom_key }}.

You problem with this snippet is your twig code.

{% for page in pages %}
        {# you do not need the curly braces inside other braces #}
        {% set images = loop(page.meta.folder) %}
        {% for image in images %}
            <div class="col-1-2">
            <a href="{{ image.url }}" data-count="{{ image.id }}" target="_blank">
            <img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.name }}">
            </a>
            </div>
        {% endfor %}
    {% endfor %}

My page would look like this:

<!--
Title: My Page Title
Folder: /path/to/a/folder
-->

My content...
lasbian commented 10 years ago

amazing. just amazing :)

Thanks!