K
K
kryamk2020-11-30 15:00:48
MODX
kryamk, 2020-11-30 15:00:48

How to check if a resource has been deleted by id in a chunk?


In the tv parameter, there is a list of id that are added manually. But some resources are removed and thus the error is displayed. How to write a condition: does a resource with this id exist (or is it published)

Here is the migx_recommended_service chunk:
<div class="col-md-6 mb-base col-xl-3" style="">
    <a class="brand" href="">
        <span class="brandtext"></span>
        <img class="img-fluid" src="" alt="">
</a>
</div>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Lunegov, 2020-12-02
@kryamk

You can try this way.
First , using the getImageList snippet , we create a comma-separated list of resource ids:


getImageList parameter instruction .
And then we use the pdoResources snippet for output , which will filter out unpublished and deleted ones.

Chunk recommended_service :
<div class="col-md-6 mb-base col-xl-3" style="">
    <a class="brand" href="">
        <span class="brandtext"></span>
        <img class="img-fluid" src="" alt="">
    </a>
</div>

But, if this was my project, then I would first try to write my own snippet, which would first check TV migx_recommended_brands: I would delete the id of non-existent resources there, filter out unpublished ones and draw a conclusion on my own.

A
Anton Tarasov, 2020-11-30
@an-tar


add &where=`{"deleted:=":"0"}` to the snippet call

I
Igor, 2020-12-10
@ig0r74

https://docs.modx.pro/komponentyi/pdotools/parser#...
I don't remember the default syntax, but something like this:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question