Helpers

    Helper usage in li3 is simple because helpers are lazy-loaded by the renderer. To use a helper in the view layer, just reference it as a property of the renderer:

    This approach means you won’t have to declare which helpers you’re planning on using. Ever. This also means that things aren’t loaded up unless (and until!) you’re actually using them.

    To create a custom helper, create a class in the directory that extends li3’s base Helper class. As a simple example, let’s create a simple helper that creates a special sort of link by creating a new file in app/extensions/helper/AwesomeHtml.php:

    One important note to consider here is that the contents of $title and $url aren’t escaped since they’re being returned raw from the helper method. Make sure you make liberal usage of the method of the Helper class to keep things safe.

    Once this has been setup, we can use the new helper as we would any of the core helpers:

    li3 gives preference to your classes over the core. If you want to create your own version of the core helpers, it’s as easy as creating a new class inside the directory with the same name.

    Also realize that in doing this, you’ll probably wish to extend the helper you’re replacing to take advantage of the functionality already there. If we took our own advice, the new helper would extend lithium\template\helper\Html and link() would be refactored to take advantage of the helper’s existing link function.