MODX Community

GetimageList need to find a parent pagetitle for sub pages at 2 different levels

Hi,

It’s time to solve this issue I never really looked at.
I need to display some page dependent logos.
Because I do not wanna re-enter many images in Migx TV for various pages, I choose to enter every images into an Migx TV of a parent pages. So we need to pickup in there what is relevant.

I’m calling the GetimageList snippet with a where condition on each child pages, so they should get the logos I need.

I’m stuck with what to put into the where condition, because that works only when we are on pages 'Brand1" or 2, etc.
This is normal because the where condition uses the current *pagetitle.

I need to make this ok for every childs too. (each child of a Brand-x must uses Brand-x *pagetitle as where condition, but itself Brand-x also)
So I need to change [[*pagetitle]] in this, into something that fits my need… but … no success until now. (UltimateParent??)
&where=`{“title_logo:contains”:"[[*pagetitle]]"}

the tree looks like (and there are 2 context, ine for Fr = web, another for Eng=eng, but it should not be a question):

 **Home (1)**
   **Parent1**
         *Brand1*
             Child11
             Child12
             Child13
        *Brand2*
            Child21
            Child22
            Child23

etc.

here’s the chunk at this time.

<ul>
        [[!getImageList?
        &tvname=`BrandsLogos`
        &tpl=`PanelLogosTpl2`
        &docid=`133`
        &randomize=`0`
		&where=`{"title_logo:contains":"[[*pagetitle]]"}` 
        ]]
</ul> 

Thanks for any help.

I think, you could use pdoField to fetch, what you need

Thank you…but…
PdoField: [[pdoField?
&id=[[*id]]
&field=id
&top=2
]]
won’t be enought
what I need into the where condition is this:
(don’t work in place) (the +thisParent comes from a custom snippet)
[[!If?
&subject=[[+thisParent]]
&operator=EQ
&operand=133
&then=[[*id]]
&else=[[+thisParent]]
]]

Because it all gets so convoluted and you already have a custom snippet, you could probably put all the code in your custom snippet and call GetimageList with $modx->runSnippet('getImageList',array(...)); from there.

The code would look something like this (untested and probably contains typos):

<?php
$thisParent = $modx->resource->get('parent');

//read the pagetitle
if ($thisParent == 133){
    //pagetitle from current resource
    $pagetitle = $modx->resource->get('pagetitle');
} else {
    //pagetitle from parent resource
    $parent = $modx->getObject('modResource', $thisParent);
    if ($parent) {
        $pagetitle = $parent->get('pagetitle');
    }
}

//Call to getImageList
if (isset($pagetitle)){
    $where_clause = '{"title_logo:contains":"'.$pagetitle.'"}';
    return $modx->runSnippet('getImageList',array('tvname'=>'BrandsLogos','tpl'=>'PanelLogosTpl2','docid'=>'133','randomize'=>'0','where'=>$where_clause));
} else {
    return '';
}

Thank you

I’ve made something in this idea. (partially like you did).