AF-BedSheetEfanUser Guide


afBedSheetEfan is a Fantom library that integrates efan templates with the afBedSheet web framework.

afBedSheetEfan uses afIoc, therefore to use the EfanTemplates service you must @Inject it into your own service / class.

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

See efan for Embedded Fantom documentation.

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 afBedSheetEfan just add it as dependency in your project's Example:

depends = ["sys 1.0", "afIoc 1.4+", "afBedSheet 1.0+", "afBedSheetEfan 1.0+", ... ]

...and that's it!

Because afBedSheetEfan defines pod meta-data for afIoc, 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(OrderedConfig 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.

Release Notes



  • New: The class name of efan renderer instances is now configurable.
  • Chg: Updated to use afIocConfig.
  • Chg: Updated to use afEfan 1.2.
  • Bug: Err msgs could produce an Err if a template file was a pod resource.


  • Chg: Updated to use afPlastic
  • Chg: Updated Errs to extend afPlastic::SrcCodeErr
  • Chg: Removed Err Page printing as BedSheet now does generic SrcCodeErr.
  • Bug: EfanCompiler was not built with contributed config values.


  • New: Code snippets from afPlastic compilation errs are also displayed in the afBedSheet Err page.
  • New: ctxVarName is now configurable.
  • Chg: Split out from efan.