Can Snippets be used in the MODx Manager Dashboard?

Is it possible to use a snippet like pdoResources to create a MODx dashboard widget that lists the unpublished resources within a specific container or folder?

Or is there a simpler way of accomplishing that?

You can create a new widget in the manager under :gear: → Dashboards → tab “Widgets” → button “Create”.

If you select the “Widget Type” = Snippet, you can put the name of a snippet in the “Widget Content”. The return value of this snippet is then displayed in the widget.

If you want to use a snippet like “pdoResources” where you have to supply different properties, you probably have to create a custom snippet and then use $modx->runSnippet() inside that snippet.

Or select the “Widget Type” = Inline PHP Widget and put code like this in the “Widget Content”:

<?php
return $modx->runSnippet('pdoResources', [
    'parents' => 1,
    'tpl' => '@INLINE <li>[[+pagetitle]] ([[+id]])</li>',
	'tplWrapper' => '@INLINE <ul>[[+output]]</ul>',
	'limit' => 0,
	'showUnpublished' => 1,
	'where' => '{"published:=":"0"}'
]);

Is there a API method of linking to a resources editing page? Or do we just paste in the full URL like: /manager/?a=resource/update&id=[[+id]]

Whenever the returned results are empty (no unpublished resources) the widget completely disappears from the dashboard.

I’m not familiar enough with the PHP. How would I display an alternate message saying <p>No unpublished resources.</p> if the results are empty?

EDIT: I found a solution in the old forums for getResources. Just added an ifempty output modifier right after the pdoResources word on line 2.

If you call $modx->runSnippet(...) in PHP, you can assign the result to a variable instead of returning it directly, and then check if the value of the variable is empty. Something like this:

<?php
// Assign the result to the variable $output
$output = $modx->runSnippet('pdoResources', [
    'parents' => 1,
    'tpl' => '@INLINE <li>[[+pagetitle]] ([[+id]])</li>',
	'tplWrapper' => '@INLINE <ul>[[+output]]</ul>',
	'limit' => 0,
	'showUnpublished' => 1,
	'where' => '{"published:=":"0"}'
]);
// Check if the result of the snippet call was empty
if (empty($output)) {
    $output = '<p>No unpublished resources.</p>';
}
return $output;