Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Documentation of grav objects

Started by Muut Archive 12 years ago · 5 replies · 346 views
12 years ago

In the post http://getgrav.org/forum#!/general:image-logo a very nice way of using the grav page object is shown.
Assuming that I have a folder pages/images, that holds all my images, I wonder if it is possible to iterate through an array of all that images. So this would be an easy way to generate a gallery.
I tried something like this:

TWIG
{% for oPage in pages.find('/images').media['*.jpg'] %}
{{ oPage.url }}
{% endfor %}

but it didn't work.
Where can I find a detailed documentation of grav objects?

12 years ago

We do intend to take our code and generate some API documentation for developers. The code in Grav is not especially complicated and it's pretty well documented as is, so the easier approach right now is to just have a look in the code to see what methods are available.

The question you are asking is completely doable, and you will see if you look in the Media Object you will see this images() method that returns an array of images as Medium objects. Then you can use Twig's array handling to loop over them:

TWIG
<ul>
{% for img in pages.find('/images').media.images %}
<li>{{ img.html }}</li>
{% endfor %}
</ul>

This will grab all the images in the directory and output them with as an <img> in an unordered list

12 years ago

Just a small issue: When the extension of the files (e.g. JPG-Files) is in uppercase, the files are not treated as images. is this intentionally so?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1280 9 years ago
Archive · by Muut Archive, 9 years ago
2 888 9 years ago
Archive · by Muut Archive, 9 years ago
2 4018 9 years ago
Archive · by Muut Archive, 9 years ago
1 2893 9 years ago
Archive · by Muut Archive, 9 years ago
3 1077 9 years ago