C
C
Cheizer2020-01-28 14:14:22
MODX
Cheizer, 2020-01-28 14:14:22

How to select resources in Fenom without a snippet?

Friends! Please tell me what I'm doing wrong.
I want to make a selection of the last added resources - goods.

There is a tree of resources - goods minishop2
-Main (1)
-Catalog (3)
---Category of goods (4)
-------Product()
......
......
---Category goods (5)
-------Product()
......
......

On the main page I call like this, I still use the snippet

{set $newproducts = $_modx->runSnippet('!msProducts', [
'parents' => 3,
'includeThumbs' => 'small,mobilesmall',
'showHidden' => 0,
'showUnpublished' => 0,
'limit' => 4,
'where' => [
    'class_key:=' => 'msProduct',
]
])}
{foreach $newproducts as $item}
{$item['menutitle']}
{/foreach}


I also tried this, without the snippet

{var $newproduct = $_modx->getResources(
    [
    'parents' => 3,
    'published' => 1, 
    'deleted' => 0, 
    'showHidden' => 0,
    'showUnpublished' => 0,
    'sortby' => 'menuindex', 
    'select' => 'id,menutitle'
    ])
 }
 
{foreach $newproduct as $item}
   {$item.menutitle}
{/foreach}


And it does not select anything in both cases, Fenom is turned on to the fullest and works everywhere, but here the design does not work, what am I doing wrong? How to write correctly?
Key, I do not want to use chunks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-01-28
@Cheizer

Why no snippet, what's the difference?
Type design

{set $products = '!pdoResources' | snippet : [
    'return' => 'json',
    ....
] | json_decode : true}
{foreach $products as $product}
...
{/foreach}

works great for your purposes.
You can also enable the settings "use $modx in Fenom" and "use PHP in Fenom", and work with the built-in methods of the system, but the first option is clearly better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question