Problems with output for a custom Dashboard Widget

I’m not sure what’s wrong with my code here. I’m guessing it’s something simple I’m just not seeing. But I’m trying to create a custom widget with useful links to files for my users to access as well as some other parts to make it easier for managers to edit without html/php experience.

I’m starting off with my widget, MyCustomDashboardSnippet, using the Snippet Type.

My initial snippet:

$output = "<ul>";
$output .= $modx->getChunk('MyCustomDashboardSnippet');
$output .= "</ul>";
return $output;

The Chunk above that gets edited by managers for content:

[[dashitem? &title=`Adding Inline Downloads` &type=`word` &link=``]]
[[dashitem? &title=`Filename Generator` &type=`xls` &link=``]]

The dashitem snippet:


$outType = '';
if ( $type = array('word','Word','doc','docx') ) : $outType = 'docx';
elseif ( $type = array('excel','Excel','xls','xlsx') ) : $outType = 'xlsx';
else : //nothing happens;

$output = $modx->getChunk('dashitem',array(
    'title'  => $title,
    'type'   => $outType,
    'link'   => $link,
return $output;

The chunk that formats the output:
<li class="[[+type]]"><a href="[[+link]]">[[+title]].[[+type]]</a></li>

For some reason, however, the output works great for everything by the $outType variable. It shows as docx regardless of whether or not I specify an Excel file or leave it blank.

Thanks for any advice.

$type = array('word','Word','doc','docx') is an assignment and not a comparison.
You probably want to use something like this:

if (in_array($type, array('word','Word','doc','docx'))) {
    $outType = 'docx';
1 Like

Yeah…that makes sense. Thanks for straightening that out!