dxw / whippet-theme-template

This repo holds the template for a Whippet-enabled theme.
2 stars 1 forks source link

Helper functions...? #19

Closed mallorydxw closed 8 years ago

mallorydxw commented 8 years ago

We need to be able to call code in a class from a template sometimes. At the moment, to call a method on an instance, you'd have to do \Dxw\MyTheme\Registrar::getInstance()->di['Dxw\\MyTheme\\MyClass']->method() which is a little too verbose.

Here are my thoughts:

  1. We can either just wrap most of the repetitive code to come up with this: f('MyClass')->method($arg1, $arg2)
  2. Or, we could allow classes to register helper functions i.e. the class's register() function calls registerHelperFunction('x', [$this, 'x']); and then the template code looks like f('x', $arg1, $arg2)

The advantage of 1 is that it's very very simple and leverages existing code and is fairly sensible-looking.

The advantage of 2 is that it makes the author of a class think about which of their methods will need to be called by template code. But we would have to think about how to namespace the methods. And this also requires additional classes to make it happen.

mallorydxw commented 8 years ago

The first helper function we should add is one to get the URI of assets.

mallorydxw commented 8 years ago
mallorydxw commented 8 years ago

We're using static methods in some places - we should replace those with this new helper system.