Help with getting started in views
Created 6 years ago by gonziis

I'm new to this framework and there are some things I can't wrap around my mind yet, It seems like there aren't enough documentation and examples covering this. Do I look just in twig or Laravel documentation? The thing is, I want to list all activated pages in my layout/view. It's such a simple thing, yet I waste so much time trying to achieve it.

{% for page in pages %} test {% endfor %} Shouldn't it be like this? What would be the correct target variable? I feel like I'm missing something major here.

william  —  6 years ago Best Answer

With twig, you could also do

{% for page in entries('pages','pages').get() %}
    {{page.title}}
{% endfor %}
william  —  6 years ago
{{ structure()
    .linkAttributesDropdown({'data-toggle': 'dropdown'})
    .listClass('nav navbar-nav navbar-right')
    .childListClass('dropdown-menu')
    .render()|raw }}
william  —  6 years ago Best Answer

With twig, you could also do

{% for page in entries('pages','pages').get() %}
    {{page.title}}
{% endfor %}
gonziis  —  6 years ago

Ok, this twig method is really what I'm looking for. Thanks! Is there any deeper documentation about getting data into views? For example, the entries(..) method. Also, what to do if I want to get only the parent pages in the loop.

ryanthompson  —  6 years ago

@gonziis the entries method is pretty well documented - it's basically all the same objects too - so a page has a title / slug / etc. As well as relations like page.parent.title.

https://pyrocms.com/documentation/streams-platform/1.3/plugin/entries

The way you "use" the object in question (here it's page) is determined by the type of field that represents the attribute you're accessing. For example the page's slug is a slug field type so you can do page.slug.humanize because of this: https://pyrocms.com/documentation/slug-field-type/2.1/usage/presenter-output#slugfieldtypepresenter-humanize