Old modules and plugins

Note: This database has been replaced by the Moodle Plugins Directory.

Block: YUI Course Files Directory Tree

Type: Block
Requires: Moodle 1.8 or later
Status: Contributed
Maintainer(s): Dean Stringer

Moodle block to display course files in a YUI TreeView widget. Includes a bunch of config settings that allow a teacher/admin to specify:
  • which folder from their files directory should be displayed
  • how deeply the folders should be crawled and made visible
  • what the name of the block should be
Note: This block only displays files and folders from the course files area. It does not include course activities, other resources likes web links, and broader control panel or course topic/week type navigation. You should consider existing blocks like "YUI Course Menu" for that purpose.


This should be a standard block installation. The only external dependencies are the YUI and JSON libraries which will already be installed with Moodle versions 1.8 or later. YUI was available in Moodle v1.7 but the JSON lib was not.
  • expand the archive into the /blocks/ folder of your Moodle root
  • visit the notifications page as an admin and the block will install

The block should perform without problem in any browser supporting the YUI library. We have specifically tested the following combinations:
  • Windows XP : Firefox 2, Firefox 3, IE7, IE6
  • Windows Vista : Firefox 3, IE7
  • Mac OS/X : Firefox 3, Safari 3
  • Ubuntu Linux : Firefox 3
The YUI libs were first introduced to Moodle mid 2006 to support AJAX work with a major upgrade to them in Aug 2007.


The block uses an OOP approach instantiating a dir_tree object through the class file included with this distribution.

After fetching the directory data from a method in the dir_tree class the data is echo'd out to the browser encoded in JSON format so that the client can invoke and render the tree using the YUI JS libraries. A static version of the tree is also written out to the client in case it doesn't support JS.

The browser needs to load dir_tree.js (url versioned so its not cached) and the YUI JS libs, and also needs a <DIV> element to pour the tree into. The browser also needs access to the css file which contains display styles for the tree.

The block class includes methods which handle generating all the HTML for these includes.

dir_tree.js is loaded with a 'defer' switch and boot-straps itself when the YAHOO.util.Event.onDOMReady event fires which then builds the tree in the browser.

When the tree is ready for display the <DIV> in the page that holds the static non-JS version is hidden and the new tree drawn in its place. A unique ID is generated for the DIVs so we can manipulate them without worrying about another instance of a dir_tree being on the same page.

One YUI feature that did change that affects the libs as shipped originally with Moodle v1.8 is the onDOMReady was not present, I've handled this by doing a try-catch and reverting to a window.load instead

The block uses a local lang folder for the interface strings, feel free to translate these and they will be included in future releases.

The dir_tree class functionality can be used by other blocks or modules. A sample use of it is included for modifying the mod/resource/type/directory class to also use the YUI tree. The class has been written in such a way that it is only loosely connected to Moodle internals and paths, after constructing the object you simply pass the wwwroot and dataroot locations into it. It should be usable outside of a Moodle environment with little effort.

Certain special folders are hidden from display, e.g. moddata & backupdata

Icons for the various file types displayed in the tree are sourced from the main /pix/f folder of Moodle and referenced in the included style.css file.

Record added by Dean Stringer - Monday, 10 November 2008, 9:59 AM
Last modified - Tuesday, 10 March 2009, 10:22 AM


  • Picture of Barry OosthuizenBarry Oosthuizen - Fri, 6 Feb 2009, 9:57 AM
    This looks nice. Does it work with 1.9.x? I get a blank screen when going to the notifications page.
  • DeeKnowDean Stringer - Fri, 6 Mar 2009, 6:03 AM
    Hi Barry, yes it's working well for us under 1.9.3. I'll drop you an IM to see if we can work out whats happening in your install and will post whatever the problem was back here later.
  • DeeKnowDean Stringer - Tue, 10 Mar 2009, 10:13 AM
    Thanx for you help resolving the probs you were having with the install Barry. I'm going to post over in the discussion forum for this block and mention the tweaks made to sort this out, and the other changes we have since made to the block at Waikato Uni. I will also update the link to the latest version of the code.
  • Picture of Pennie BaconPennie Bacon - Fri, 27 Mar 2009, 1:30 PM
    Hi.. I have 1.9.4 and I get the blank white screen on the Notification /.. I have read all of the discussions but I cant seem to resolve the problem.
  • Picture of Christian MornardChristian Mornard - Tue, 21 Apr 2009, 5:32 PM
    I have installed the block successfully on Moodle 1.9.3 on a test machine. Now, when I try to install it on our two production servers (one in 1.9.2 and one in 1.9.3), the block appears as 'title' in the block list and the configuration page is unavailable. I assume it is a language setting issue but I can't figure it out. I have checked the language settings in Moodle and they are identical to the ones on the test server. I wonder if the problem is in the template I use, the Apache configuration or the MySQL charset and collation. The shell environment variables seem identical on both servers.

    I am running Moodle 1.9.2 and 1.9.3 on SuSE Linux Enterprise Server 10 SP2. The frontend is running Apache 2.2.3. The backend is a MySQL 5.0.26 database. PHP version is 5.2.5

    Any clue?

    Thanks in advance.
  • Picture of Christian MornardChristian Mornard - Tue, 21 Apr 2009, 9:53 PM
    For some reason, this editor converts the square brackets sad.
    The string displayed in the block list is [ [ title ] ]

  • Picture of Christian MornardChristian Mornard - Wed, 22 Apr 2009, 10:34 PM
    I am a bit further. I managed to have the block title displayed by replacing <? with <?php in lang/en_utf8/block_dir_tree.php

    Not sure why I didn't need it on my test server, though. Probably a setting in PHP.ini or in httpd.conf.

    Now, I need to understand why the config form is still not displayed. All I see is : "Configuring a Course Files block" but nothing under.
  • Picture of Christian MornardChristian Mornard - Wed, 22 Apr 2009, 11:06 PM
    Turning Moodle debugging on shows this message:
    "Parse error: syntax error, unexpected $end in /srv/www/htdocs/blocks/dir_tree/config_instance.html on line 91"

    Replacing the '<?=' with '<?php echo' solved the problem.

    Hope this helps if you come across the same issue.
  • Picture of Christian MornardChristian Mornard - Wed, 22 Apr 2009, 11:36 PM
    Found it! It is a setting in php.ini

    short_open_tag = On

    I had it On on my test server but Off on the production server.
    That permits the usage of '<?' and '<?=' instead of '<?php' and '<?php echo'

    One learns every day. It took me three days to figure this one out.

    Case closed.
  • Picture of Nadav KavalerchikNadav Kavalerchik - Sun, 12 Jul 2009, 12:21 AM
    thank you for this beautiful block smile

    i have translated it into hebrew and patched it to support RTL too
    here is a link to the rtl new version (that works fine with moodle 1.9.x btw.)
  • Picture of Alex LeeAlex Lee - Thu, 4 Feb 2010, 6:44 PM
    This looks great. I have tried installing on Moodle 1.9.7 and get these errors, with both of the downloads on this page. Any ideas?

    Notice: Trying to get property of non-object in /srv/www/htdocs/lrtmoodle/blocks/dir_tree/block_dir_tree.php on line 44

    Notice: Trying to get property of non-object in /srv/www/htdocs/lrtmoodle/blocks/dir_tree/block_dir_tree.php on line 67

    Notice: Trying to get property of non-object in /srv/www/htdocs/lrtmoodle/blocks/dir_tree/block_dir_tree.php on line 70

  • nothin' to do Alberto Juliao - Wed, 22 Dec 2010, 12:07 AM
    Hello, I found this very wonderful, I installed it and adapted for a better css style, but I have a problem now, Our website uses mootools and somehow is avoiding to display the block, I went to the header.html of current theme and deleted the script line where is called the mootools.js and it showed normally, but I need help to find a way to fix this issue, I went to the block_dir_tree.php and on line 24 we have this:
    require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview'));
    First I commented the line and it the block appeared normally showing the files and folders, but didn't show the expandable option on folder and sub-files of folders. Then I changed the first attribute (yui_yahoo) to "yui_container" and the same thing happened, showing all files and folders but no expandable option (left icon on folders).. Is there a way to make this work with mootools? I will appreciate it so much. Thanks for reading.