BedSheet Efan is a Fantom library that integrates efan templates with the BedSheet web framework.

BedSheet Efan uses IoC, therefore to use the EfanTemplates service you must @Inject it into your own service / class.

BedSheet Efan provides a cache of your compiled efan templates, integrates into BedSheet's Err 500 page and lets you contribute efan view helpers on an application level.

See efan for Embedded Fantom documentation.

ALIEN-AID: Replace BedSheetEfan with efanXtra to create managed libraries of reusable Embedded Fantom (efan) components!


Install BedSheet efan with the Fantom Repository Manager ( fanr ):

C:\> fanr install -r afBedSheetEfan

To use in a Fantom project, add a dependency to

depends = ["sys 1.0", ..., "afBedSheetEfan 1.0+"]


Full API & fandocs are available on the Status302 repository.

Quick Start


<% ctx.times |i| { %>
<% } %>
Merry Christmas!

using afIoc::Inject
using afBedSheet::Text
using afBedSheetEfan::EfanTemplates

class IndexPage {

  @Inject private EfanTemplates? efan

  Text render() {
    template := efan.renderFromFile(`res/index.efan`.toFile, 3)

    // --> Ho! Ho! Ho! Merry Christmas!
    return Text.fromPlain(template)


To use BedSheetEfan just add it as dependency in your project's Example:

depends = ["sys 1.0", ... "afBedSheetEfan 1.0+" ]

...and that's it!

Because BedSheetEfan defines pod meta-data for IoC, no more configuration or setup is required.

View Helpers

Efan lets you provide view helpers for common tasks. View helpers are mixins that your efan template can extend, giving your templates access to commonly used methods. Example, for escaping XML:

Contribute View Helpers in your AppModule:

@Contribute { serviceType=EfanViewHelpers# }
static Void contrib(Configuration conf) {

All templates then have access to methods on XmlViewHelper:

  Hello <%= x( %>!

Err Reporting

afEfan automatically hooks into afBedSheet to give detailed reports on efan compilation and runtime errors. The reports are added to the default afBedSheet Err500 page.

Efan Compilation Err:
  file:/C:/Projects/Fantom/Efan/test/app/compilationErr.efan : Line 17
    - Unknown variable 'dude'

    12: Five space-worthy orbiters were built; two were destroyed in mission accidents. The Space...
    13: </textarea><br/>
    14:         <input id="submitButton" type="button" value="Submit">
    15:     </form>
==> 17: <% dude %>
    18: <script type="text/javascript">
    19:     <%# the host domain where the scanner is located %>
    21:     var plagueHost = "";
    22:     console.debug(plagueHost);

Fair Usage Policy!

Efan works by dynamically generating Fantom source code and compiling it into a Fantom type. Because types can not be unloaded, if you were compile 1000s of efan templates, it could be considered a memory leak.

For this reason, templates compiled from files are cached and reused, therefore posing no risk in your typical web application(*). But templates compiled from Strs are not cached and so calls to this method should be made judiciously.

(*) If a template file seen to be modified, the efan template is re-compiled on the fly. This is fine in dev, but be weary of modifying template files in live.