Search code examples
modxmodx-revolution

ModX Get Resources not using template


Newbie to modx and I am trying to build an image slider in Modx Revo. I am using Get resources but it does not output the template file. What am I doing wrong? This is my code:

[[getResources? 
        &resources=`[[*slide-img]]` 
        &parents=`-1` 
        &depth=`0` 
        &limit=`0` 
        &tpl=`slides` 
        &sortby=`FIELD(modResource.id,[[*slide-img]])` 
        &sortdir=`ASC`
        &includeTVs=`1` &processTVs=`1` &tvPrefix=`tv.`
    ]]

Solution

  • From what I understand, you're trying to get all images from ressources in the resource tree. And show them in an image slider.

    I guess you will have the javaScript for the image slider already present. So there is how to get the images.

    You have a TV called slide-img, right? Good. Make sure it's output format is text.

    If you refer to that image inside of a page that carries that TV, you call it like this

    <img src="[[*slide-image]]" alt="some Image" />
    

    If you call it in a chunk (what you will do when using getResources), you call the image like this:

    <img src="[[+tv.slide-image]]" alt="some Image" />
    

    See the difference? * is for the TV inside of the same page, + is the correct call for a placeholder. So if you're using getResources, it will put everything you query into the placeholders in your microtemplate (we call that chunk in MODX terms)

    So your getResources call might look like this:

    [[getResources? 
        &parents=`-1` (the place from where getResources will dig down the tree)
        &depth=`0` (how deep will it dig?)
        &limit=`0` (only the default 5? no! :) )
        &tpl=`slides` (this is your chunk, right?)
        &sortby=`FIELD(modResource.id,[[*slide-img]])` (you will sort by the file name and folder, is that right?)
        &sortdir=`ASC`
        &includeTVs=`1` &processTVs=`1` &tvPrefix=`tv.` (right, right, tv. is already the default value)
    ]]