getResources issues (noob questions)

Hi, I’m new to ModX having only worked with WordPress before. I’m remaking a front page for a client in ModX. They have used TVs and getResources to display custom or dynamic content on their site. I’m now trying to achieve a similar thing for their new front page. They have a news feed where all their posts get shown, this is done with getResources. I tried to use this: [[!getResources? &parents=[[*id]]&tpl=newstest&limit=0&includeTVs=1&processTVs=1&tvPrefix=`` &depth=2]] I have this code inside the front page template file, and the posts for which I’m trying to display are nested two layers down inside containers. I can’t get this to work, maybe it’s because I need everything to be published and not hidden from menus (yepp when I try debug=true, and the resource specified it then show an array)? If I specify a direct resource inside the getResources then it shows up, so maybe something up with the parent value?I also wondered if I can use the getResources code (from above) directly inside a resource and not only inside a template file? I’ve set up the new page like: header, content and footer and used that template file for the entire page, and then just added the code inside the resource using that template.

1 Like

Hi @Krullmizter,

Welcome to the MODX forums!

The tag you’re using inside the parents parameter i.e. [[*id]] returns the current page id.
So if that’s a snippet call you’ve taken from another page then it might be referencing the wrong parent.

Instead of using [[*id]] you could just use the id number of the parent resource the data is under.
Have I understood you correctly?

3 Likes

So, it seems to be the parent value. Use the id/number of the resource-container those posts are in and it should be directed correctly.

You can, I believe, also call the getresources from a resource rather than in the template, Modx has a lot of pages that are just a call or two.

Yeah thx that seemed to solve the problem. Now I also can use the previously made posts to show on the new front page instead of them having to re-create or move the old ones. I read somewhere though that I should be using getPage (to get pagination) instead of getResources, do you know anything about this?

Yepp thx got it working!

Yup you can use getPage if you’d like to use pagination.

getPage will actually wrap around the getResources snippet and paginate the results.
So, it would be something along the lines of:

[[!getPage?
    &element=`getResources`
    &parents=`[[*id]]`
    &tpl=`newstest`
    &limit=`0`
    &includeTVs=`1`
    &processTVs=`1`
    &tvPrefix=``
    &depth=`2`
]]

You’ll need to add some extra parameters depending on what you’re after, such as how many results in each page etc and you’ll need to define a div to use for the page numbers.

Have a look at this for all the details:
https://docs.modx.com/extras/revo/getpage

1 Like