Data in Admin, display on site


#1

Hi,

I’m new to grav and enjoying it so far… I have a question.

In admin I need to add option Apartments, this should contain collections of apartments…
So a single apartment should have Id, Name, description, images.
In admin I need to have the option to add as much of them as needed and also to delete them.
On the site I will display apartments in descending order, similar to a list of blog posts.

Can someone point me a way to do this that is straightforward and explain since I can’t find any examples of something similar?

Thank you.


#2

Hi,

for anyone who is looking for some answers, i managed to get around it.

So in pages i created an apartments folder and inside of that every individual apartment goes. In the theme whatever you named your .md file you can put the same file in templates (only .html.twih extension).

To be able to add apartments via admin, in /user/blueprints/pages i created apartment.yaml and apartments.yaml files. There i added form elements that I need.

Later in my templates i would select all appartments like this:
{% for apartment in page.find(’/apartments’).children %}

{% endfor %}

Like this I can configure apartments as a whole, and also add as much of them individually as I need.

It’s a little hard to get used to the fact that there is no database, more so if you come from Laravel or simmilar frameworks like I do, :smiley:

BR, Daniel.


#3

Thanks for sharing your solution. The forum does not appear to be very active.