Ticket #2 (closed: fixed)
Add helper object for standard helper functions
| Reported by: | bbangert | Owned by: | bbangert |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.8 |
| Component: | helpers | Version: | svn |
| Severity: | normal | Keywords: | |
| Cc: |
Description
To ease the use of helper functions throughout templates, a helper object, possibly available as a Myghty global 'h' should be utilized. This helper object would start out populated with some standard Pylons helper functions.
Additional 3rd party or custom helper functions would be affixed to the h object, likely in the controller to assist with controller specific templates.
While using one letter object names can be odd, especially in Python, I believe it makes sense in this context since these functions will be used so often it would be extremely frustrating and lots of boiler-plate to extend the name of the base object much.
Usage:
#controllers/content.py from mylibrary import myhelpers class ContentController(BaseController): def __before__(self, action, **params): self.h.myhelpers = myhelpers #... actions as normal...
Then inside a template:
Welcome <% h.myhelpers.people() %> etc...
Alternative Usage
Since the controller is instantiated per request, having to attach the function lib every single time is likely wasteful in some way. It'd probably make more sense to allow the developer to customize their helper libraries elsewhere.