b:files

<b:files>...</b:files>

Gets files and directories under site's files-folder

<b:files> is used to get file information from any file or folder under files folder in your site root. Like with other listed data, contents of the tag will be repeated for each found file.

To show and execute something before and after the files, you can use <b:before> and <b:after> tags inside the <b:files> tag. When no data is received, content inside the <b:nodata> tag will be shown and executed.

<b:files> has various attributes that help you limit the files to match the properties you want.

b:files tags

b:files.name

<b:files.name />
Displays the file name

b:files.path

<b:files.path />
Displays path to the file

b:files.url

<b:files.url />
Displays url to the file

b:files.type

<b:files.type />
Displays the file type

b:files.size

<b:files.size />
Displays the file size

b:files.created

<b:files.created />
Displays the creation time of the file

b:files.modified

<b:files.modified />
Displays the last modification time of the file

Attributes

name

What variable name to use inside the tag to refer to the requested files. You can use the same name only once on a page, and the name cannot be any of the reserved names.

parent

(optional)

Get files from a certain folder. Parent path should be relative to the site's files-folder. Absolute urls (http://www.mydomain.com/files/images/) won't work.

See example 2

type

(optional)

get only certain types of files. You can use the filetype or one of the predefined group as a value. Use comma to separate different file types.

Predefined types:

  • folder (only folders)
  • file (everything else than a folder)
  • image (tiff, eps, bmp, psd, ai, png, gif, jpg)
  • webimage (png, gif, jpg)
  • document (txt, rtf, doc, pdf)
  • code (css, js, html, php)
  • movie (mpg, mpeg, m4v, wmv, avi, rm)

orderby

(optional)

Orders received files by this information:

  • name
  • type
  • created
  • modified
  • size

You can alter the direction of ordering with the attribute direction.

direction

(optional)

Defines ordering direction.

Valid values are asc (ascending) and desc (descending). Default is ascending.

limit

(optional)
A number of files to list. Limit is often used together with offset to create pagination.

offset

(optional)
How many files to jump over from the begin. Offset is often used together with limit to create pagination.

nocache

(optional)

If this attribute is defined, the <b:files> will not be cached and will be executed on each page view.

Examples

Listing files

Here's a basic file listing

<h3>Our files</h3>
<b:files name="file">
  <b:before><ul></b:before>
  <li>
      <a href="<b:file.url/>">
        <b:file.name/>
      </a>
  </li>
  <b:after></u></b:before>
</b:files>
HTML source output
<h3>Our files</h3>
<ul>
  <li>
      <a href="/files/cheese.jpg">
        cheese.jpg
      </a>
  </li>
  <li>
      <a href="/files/products.pdf">
        products.pdf
      </a>
  </li>
</u>

Retrieving files from a certain folder

Here we list files from a folder called "board" under "press" folder and in an order that newest come first in the list

<h3>Load press photos of our board members</h3>
<b:files name="file" parent="press/board/" orderby="created" direction="DESC">
   <b:before><ul></b:before>
   <li>
     <a href="<b:file.url/>"><b:file.name/></a> (<b:file.size/>)
     - published <b:format.date format="M jS Y"><b:file.created/></b:format.date>
  </li>
  <b:after></u></b:before>
</b:files>
HTML source output
<h3>Load press photos of our board members</h3>
<ul>
   <li>
      <a href="/files/press/board/dilbert.jpg">dilbert.jpg</a> (120 kB)
     - published May 21st 2009
   </li>
   <li>
      <a href="/files/press/board/dogbert.jpg">dogbert.jpg</a> (1.1 MB)
     - published May 21st 2009
   </li>
   <li>
      <a href="/files/press/board/Pointy_Haired_Boss.jpg">Pointy-Haired_Boss.jpg</a> (2.4 GB)
     - published May 21st 2009
   </li>
</u>