Sorcerer's Tower

Link lexicon verb for Fusebox 5

I have created a simple custom verb which allows you to link specified resource files from circuit.xml, without having to go to the bother of writing it all in a script and including it.

For example, you can do this:

<cf:link resource="/res/bubbles.css"/>
<cf:link resource="/res/bubbles.js"/>

And it will convert that and place the following inside your HTML head:

<link rel="stylesheet" type="text/css" href="/res/bubbles.css"/>
<script type="text/javascript" src="/res/bubbles.js"></script>

This should be useful if you have a lot of different circuits that all have unique styles and scripts, and you'd rather avoid putting lots of conditional statements in your layout pages.


If you haven't used lexicons before, they're actually really simple (once you have it explained to you - thanks to Nick Tong for helping me).

Here is how to setup and use them:

  1. Create a lexicon directory in your application root (the same place as your circuits directory) - note: it is singular lexicon, NOT lexicons
  2. Create the folder for the verbs to go in. For example, you could use ht, since it is related to hypertext, although personally I've just plonked it in an existing cf one.
  3. Put the link.cfm verb file into this directory. So, you could have the following: {webroot}/myapp/lexicon/ht/link.cfm
  4. In the relevant circuit.xml, add xmlns:ht="ht/" to the root circuit tag at the top of the document (where the first ht is the prefix, and the ht/ is the sub-directory inside your lexicon folder).
  5. Use the tag like this: <ht:link resource="/styles/default.css"/>

And that's all there is to it!


Here is a simple example circuit:

<circuit access="public" xmlns:ht="ht/">

<fuseaction name="main">
  <ht:link resource="/styles/default.css"/>
  ...
 </fuseaction>

</circuit>

Download: link.cfm.zip (<1KB)