0
votes

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.`
    ]]
2

2 Answers

0
votes

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)
]]
0
votes

getResources is a snippet used primarily to list documents, not images. A document (of type HTML, XML, CSS or JSON, to name a few) is created in the document tree in the manager and represents an example of a resource that you can get with getResources snippet.

Even if it is possible somehow to put an image as a document (which I doubt), it is not a common way anyway. Usually you want to attach an image to a document via template variable of corresponding type. For a slider particularly, you need many images, not one. So, you might need something specific like Gallery Extra to manage and output your images. Check out gallery section too. Note that basic version of MODX you have just installed isn't fully functional. We have to install extras to use MODX properly. Usually I install up to 30 extras.

Also your snippet call looks weird to me:

&resources=`[[*slide-img]]`

I don't know what the content of your template variable slide-img is but it should be a comma-separated list of resource ids like 2,4,6,34. Probably, in your case you have something different like image url and the snippet call silently crashes or just outputs nothing.