gonziis - 3 months ago

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.

Answer

william - 3 months ago

With twig, you could also do

{% for page in entries('pages','pages').get() %}
    {{page.title}}
{% endfor %}

william - 3 months ago

{{ structure()
    .linkAttributesDropdown({'data-toggle': 'dropdown'})
    .listClass('nav navbar-nav navbar-right')
    .childListClass('dropdown-menu')
    .render()|raw }}

william - 3 months ago

With twig, you could also do

{% for page in entries('pages','pages').get() %}
    {{page.title}}
{% endfor %}

gonziis - 3 months 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 - 3 months 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