We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi all,

    Some time ago I figured out how to place new site content (resources, articles) in a dashboard widget. I thought I share it with you all.

    In my case I would like a dashboard widget which shows me the newest 10 resources from a container (in my case these are the latest 10 nominations). It looks like this:



    1. Create a dashboard widget
    Widget type: inline PHP widget
    Widget content:
    $output = $modx->runSnippet('getResources',array(
       'parents' => '938',
       'showHidden' => '0',
       'limit' => '10',
       'includeContent' => '1',
       'sortby' => 'id',
       'where' => '{"template:=":7}',
       'tpl' => 'newResourcesWidget'
    ));
    return $output;


    2 Create chunk newResourcesWidget:

    <strong>[[+longtitle]] on [[+createdon:strtotime:date=`%e %b %Y om %R`]]</strong>
    <br />
    <a href="[[++manager_url]]?a=resource/update&id=[[+id]]">[[+pagetitle]]</a> - [[+content]]
    <br /><br />
    


    Clicking on the link takes you directly to the page in the manager.

    Of course some CSS could be added to make it look more fancy.
    Feel free to alter the code to your needs! [ed. note: michelle84 last edited this post 10 years, 8 months ago.]
      • 20413
      • 2,877 Posts
      Nice! Thanks for sharing! smiley
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 46630
        • 40 Posts
        Nice!

        If you want to get just titles of the latest resources, you could use this code for your template chunk:

        <a href="[[++manager_url]]?a=30&id=[[+id]]">[[+pagetitle]]</a><br />


        This is much shorter and you do not have to write the URL of the website and the manager, just use the manager tag. In my MODX 2.2.14 the "?a=30" part of the url comes before the id of the resource.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The position of the key->value pairs doesn't matter. They all get dumped into PHP's $_REQUEST or $_GET array anyway.

          For 2.3, the action would be a=resource/update
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org