Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Commit

Permalink
bugfix: options did not get passed in to macro templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Roessl committed Oct 31, 2007
1 parent 6914252 commit 01dc6ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
13 changes: 8 additions & 5 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changes for z3c.viewtemplate
============================


Version 0.3.1 (2007-10-31)
========================

- bugfix: options did not get passed in to macro templates


Version 0.3.0 (2007-09-27)
========================

Expand All @@ -10,12 +17,8 @@ Version 0.3.0 (2007-09-27)

- no dev release anymore


Version 0.2 (2007-05-01)
========================

- Fire a BeforeUpdateEvent in the base views. This requires zope 3.4





2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages

setup(name='z3c.viewtemplate',
version='0.3.0',
version='0.3.1',
author = "Zope Community",
author_email = "zope3-dev@zope.org",
description = open("README.txt").read(),
Expand Down
14 changes: 11 additions & 3 deletions src/z3c/viewtemplate/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ one.
>>> print templatedView()
<div>view</div>


Use of macros.

>>> macroTemplate = os.path.join(temp_dir, 'macroTemplate.pt')
Expand All @@ -120,14 +121,21 @@ Use of macros.
... <div>macro1</div>
... </metal:block>
... <metal:block define-macro="macro2">
... <div>macro2</div>
... <div tal:content="options/foo">macro2</div>
... </metal:block>
... ''')

>>> factory = TemplateFactory(macroTemplate, 'macro1', 'text/html')
>>> print factory(view, request)()
<div>macro1</div>

Since it is possible to pass options to the viewlet let's prove if this
is possible for macros as well::

>>> factory = TemplateFactory(macroTemplate, 'macro2', 'text/html')
>>> print factory(view, request)(foo='bar')
<div>bar</div>


Why didn't we use named templates from the ``zope.formlib`` package?

Expand Down Expand Up @@ -175,6 +183,6 @@ created earlier in this test.
>>> component.provideAdapter(factory,
... (IMyUseOfView, IDefaultBrowserLayer),
... IPageTemplate)
>>> print simple.template()
<div>macro2</div>
>>> print simple.template(foo='bar')
<div>bar</div>

4 changes: 3 additions & 1 deletion src/z3c/viewtemplate/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __call__(self, *args, **kwargs):
raise KeyError('Macro "%s" not found in file "%s"'% (
self.macroName, self.template.filename))
output = StringIO(u'')
namespace = self.template.pt_getContext(self.view, self.request)
namespace = self.template.pt_getContext(self.view,
self.request,
options=kwargs)
context = self.template.pt_getEngineContext(namespace)
TALInterpreter(program, None,
context, output, tal=True, showtal=False,
Expand Down

0 comments on commit 01dc6ab

Please sign in to comment.