CMS help pages
  
You are here: Home > Developers > How to build templates > Links to files

Link to files

type=fileSource/fileTarget

When the user right-clicks on the SOURCE tag they will get a simple pop up to allow them to select one of their uploaded files. When the site is published, the file will be copied to the target website.

Example:
<c>
<div>
Select the spreadsheet file:
<cms type=fileSource id=file1 scope=section filter=.xls>
</div>
</c>

<a href="<cms type=fileTarget id=file1>" target=new>Click here to open the spreadsheet in a new window</a>

Filtering the files list

To make life easier for clients (and reduce support calls) you can filter the list of files produced by the filesource tag. Include the parameter filter, followed by a comma separated list of filters. The list of files will be restricted to files that contain any of the filter strings.Example 1:

<cms type=filesource id=my_file scope=page filter=.swf>

This will only show files with the extension '.swf'.Example 2:

<cms type="filesource" filter="offers,specials" id="my_file" scope="section">

This will only show files containing the string 'offers' or the string 'specials'.

Example 3:

<cms type=filesource filter=stylesheet,.css id=my_file scope=page>

This will only show files containing the string 'stylesheet' or the string '.css'.

Setting a default file

A common use of the CMS FILE TAG is to allow users to select a banner image for a page or a folder. This is easy enough to do, but users don't always remember to select the banner image when they create a page. You can set a default file using the following code:

...
<head>
<script type="text/javascript">
function docOnLoad(){
  var e=document.getElementById("bannerImage");
  if(e.src.match(/undefined/i)||e.src.match(/spacer.gif/i)){
    e.src="
<cms type=filetarget id=default_banner scope=all>";
  }
}
</script>
</head>
<body onload="docOnLoad()">
  ...
  ...
  <img id="bannerImage" src="<cms id=bannerImage type=filetarget  scope=page>" width="750" height="150" alt="">
  ...
  ...

<c>
Default banner image:
<cms type=filesource id=default_banner scope=all><br>
Banner image for this page:
<si5 id="bannerImage" type="filesource" scope="page">
  ...
  ...
</body>
</html>