views:

45

answers:

1

i want to create a widget depending on the class of the object, is there a simple way to do that in mako? for example

class A might have attributes A and B

while

class B might have attributes A, B and C

is there a pattern for this?

i want to make a super class that they but inherit, but if I have a function print and call it by calling obj.print(), but i don't want to put template code into class functions

for example, i have a widget that goes

<div>obj.a</div>
<div>obj.b</div>
<div>obj.c</div>
<div>obj.d</div>

but if it's object B, i want it to go

<div>obj.a</div>
<div>obj.b</div>
<div>obj.c</div>

etc, but was wondering if theres a clean way to do it

+1  A: 

Make a method which returns [a, b] in class A and [a, b, c] in class B.

Then you can do:

% for stuff in thing.return_list_of_stuff:
    <div>${stuff}</div>
% endfor

(I've never used mako, so the syntax might be incorect.)

Seth
That is what I was thinking, but harder to deal with more customization
Timmy