[Grok-dev] "Apply" a pagetemplate to an object and get html back
Achim Domma
domma at procoders.net
Sat Jul 19 11:26:43 EDT 2008
Am 19.07.2008 um 17:01 schrieb Lennart Regebro:
> On Sat, Jul 19, 2008 at 09:41, Achim Domma <domma at procoders.net>
> wrote:
>> I don't understand your solution, but perhaps my question was not
>> exact
>> enougth. I have
>>
>> class Page(grok.Model):
>> ...
>>
>> class Event(grok.Model):
>> ...
>>
>> class TheView(grok.View):
>> grok.context(Page)
>> def render_body(self):
>> here I use textile/markdown to format the body of
>> the page. and I also want to iterate over a list of
>> events and want to create a html snippet for each on.
>>
>>
>> In the page template of TheView I will use the render_body method.
>> So I
>> could create a view for Event but then I still have to call them
>> to produce
>> some html for me.
>
> Yup, that's exactly how you do it. Indeed you need to be more exact
> with the qeustion. :)
TheView displays a page, and the page template for the page uses
render_body to insert a html block for the current page. In that html
block I would like to display a list of events. The pseudo code would
look like this:
def render_body(self):
html = format_body_with_markdown(self.body)
events = "<div>"
foreach event in self.getEvents():
evtents += convert_event_to_html(event)
events = "</div>"
return html.replace("PLACEHOLDER", events)
My problem is the convert_event_to_html method, if I want to use a
page template to layout the events. Hope this makes my problem more
clear?!
Achim
More information about the Grok-dev
mailing list