ClueGun 0.2 by Agendaless Consulting (based on ClueBin by ServerZen Software).
Main page
Paste Entry
Author: yeah man
Date: 11/13/08 at 13:38:13
Format: Smarty
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
15:48  	mcdonc:  	i think i have decided on a "correct" way to invoke templates from bfg views
15:49 	mcdonc: 	particularly templates that use macros
15:49 	mcdonc: 	a) make an "API" class that you pass context, request, and the "main template" name into
15:50 	mcdonc: 	this class does a self.main = get_template(main_template_name)
15:50 	mcdonc: 	in its __init__
15:50 	mcdonc: 	other convenience things are set as necessary
15:51 	mcdonc: 	(e.g. self.context_url = model_url(context, request))
15:51 	mcdonc: 	b) when the view is invoked, you make an instance of API, then call "render_template_to_response" with the API and your required keywords
15:52 	mcdonc: 	e.g...
15:52 	mcdonc: 	api = API(context, request, 'templates/main_template.pt')
15:52 	mcdonc: 	return render_template_to_response('templates/mytemplate.pt', api=api, stuff=[1,2,3])
15:53 	mcdonc: 	the templates then do
15:53 	mcdonc: 	metal:use-macro="api.main.macros['master']"
15:54 	ddurham: 	mcdonc: I'm scheduled to do a lightning talk at chipy tonight ... all thanks to your help early in my python career
15:54 	mcdonc: 	and tal:attributes="{$api.context_url}" and so on
Previous Pastes