where to stick custom templates

1 view
Skip to first unread message

Tim Hoffman

unread,
Feb 26, 2010, 4:20:56 AM2/26/10
to ish.io
Hi

Docs mention

"Each part of the form can be overridden by using a local formish
template directory. Allowing you to provide your own suite of
templates."

Where might that be, and what might it be called ;-)

Just using formish out of the box on app engine.

See ya

T

Matt Goodall

unread,
Feb 26, 2010, 7:02:05 AM2/26/10
to is...@googlegroups.com

Hi,

I'm not sure if there's an example of this in formish but it's a
matter of adding another template directory in front of (in terms of
lookup order) formish's default template directory and then adding the
template files you want to override to your template directory.

If you look in the formish.renderer module you'll see how the default
renderer is built. Unfortunately, it's not very extensible at the
moment but that's something that can be fixed easily.

So, you would have your own version of formish.renderer.Renderer that
lists two directories to use during template lookup with yours listed
first, e.g.

class Renderer(object):

def __init__(self):
self.lookup = mako.lookup.TemplateLookup(
directories=['myapp/templates', # looks here first
resource_filename('formish',
'templates/mako')],
input_encoding='utf-8', default_filters=['unicode', 'h']
)

def __call__(self, template, args):
return self.lookup.get_template(template).render_unicode(**args)

Then, you create your form by passing an instance of this renderer and
use the form in the usual way.

renderer = Renderer()
schema = schemaish.Structure(...)
form = formish.Form(schema, renderer=renderer)

(There's no need to create a new Renderer for each form, a single
instance will do. Create one in a module somewhere and use it
everywhere.)

Once you've got that in place you need to identify what formish
template to override, mirror the directory structure, and add your
version of the template.

$ mkdir -p myapp/templates/formish/form
$ echo '<p>Ha, no more form!</p>' > myapp/templates/formish/form/main.html

Now when the form is rendered it will find *your* version of the
formish/form/main.html template and use it.

Of course, you'd probably copy the formish version to your directory
structure and make a couple of tweaks. My example is just silly and
only to demonstrate.

One thing that would make this process a little simpler is if
formish.renderer.Renderer allowed you to insert some application
template directories. I'll probably push a change for that in a few
minutes.

Hope that helps.

- Matt

Matt Goodall

unread,
Feb 26, 2010, 7:47:18 AM2/26/10
to is...@googlegroups.com
On 26 February 2010 12:02, Matt Goodall <matt.g...@gmail.com> wrote:

> One thing that would make this process a little simpler is if
> formish.renderer.Renderer allowed you to insert some application
> template directories. I'll probably push a change for that in a few
> minutes.

Just pushed that change,
http://github.com/ish/formish/commit/63e42c53a38bd8825b6ba569e16e055307188081.
Not part of a release yet.

Setting up your custom renderer should now be as easy as:

import restish.renderer
renderer = restish.renderer.Renderer(['myapp/templates'])

- Matt

Tim Hoffman

unread,
Feb 26, 2010, 10:58:13 AM2/26/10
to ish.io
Hi

Just grabbed it and it works a treat.

Thanks

T

On Feb 26, 8:47 pm, Matt Goodall <matt.good...@gmail.com> wrote:


> On 26 February 2010 12:02, Matt Goodall <matt.good...@gmail.com> wrote:
>
> > One thing that would make this process a little simpler is if
> > formish.renderer.Renderer allowed you to insert some application
> > template directories. I'll probably push a change for that in a few
> > minutes.
>

> Just pushed that change,http://github.com/ish/formish/commit/63e42c53a38bd8825b6ba569e16e0553....

Reply all
Reply to author
Forward
0 new messages