I understand that. You can define at the top of layout and do {{def block(name): try: name() return False except: return True pass return}}
and do #layout.html <html><head> <title>{{if block(title):}}index{{pass}} - mysite.com</title> </head><body> <div id="left_colunmn"># some navigation links here</div> <div id="content">{{include}}</div> <div id="right_column"> {{if block(right_col):}} <h3>Latest Comments</h3> <ul>....</ul> <h3>Latest RSS Feeds</h3> <ul>....</ul> {{pass}} </div> </body></html> #default/search.html {{def right_col():}} ... search options {{=search_form}} <h4>Search Tips</h4> <ul><li>Try using keywords</li></ul> {{return}} {{extend 'layout.html'}} {{=BEAUTIFY(results)}} On Nov 23, 12:08 am, Thadeus Burgess <thade...@thadeusb.com> wrote: > I think you're trying to use blocks incorrectly. Blocks are defined in a > base template that is to be extended. When the extending template declares a > block that exists in the parent template, it will replace everything in > between the parent block, like inheritance and overriding. However the > parent template can display a default value for the block, in case it does > not get overridden. > > A case example, say on every page I want to display the latest posts, > comments, and updated RSS feeds. However on my search page, I want to > replace this column with a search form instead, so I display a lengthy form > so you can select between categories, tags, search phrase, etc. > > I do not believe this is possible in pure template code in web2py, you have > to do something from your controller such as response.right_column = > "latest_stuff.html", and then if you want to set it to something else you > have to set it from your specific action, def search(): > response.right_column = "default/search_sidebar.html". I don't like this > because it starts to blend the line between a Controller, and a View. > > With blocks this is how it would be implemented, all from within the views. > > #layout.html > > <html><head> > > <title>{{block title}}index{{endblock}} - mysite.com</title> > > </head><body> > > <div id="left_colunmn"># some navigation links here</div> > > <div id="content">{{include}}</div> > > <div id="right_column"> > {{block right_col}} > > <h3>Latest Comments</h3> > > <ul>....</ul> > > <h3>Latest RSS Feeds</h3> > > <ul>....</ul> > > {{endblock}} > </div> > > #default/search.html > > {{block right_col}} > > ... search options > > {{=search_form}} > > <h4>Search Tips</h4> > <ul><li>Try using keywords</li></ul> > > {{endblock}} > > {{=BEAUTIFY(results)}} > > </body></html> > > -Thadeus > > On Sun, Nov 22, 2009 at 10:03 PM, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > Here is my problem with blocks: > > > #extended > > {{block a}}hello{{endblock}} world {{block b}}hello{{endblock}} > > > #extending > > {{block a}}HELLO{{endblock}} WORLD {{block b}}HELLO{{endblock}} > > > where does WORLD go? It gets lost. Blocks are convenient and not well > > defined. > > > I believe {{def a():}}HELLO{{return}}, the current web2py way, is more > > Pythonic and it is better defined. > > > Massimo > > > On Nov 22, 9:46 pm, Thadeus Burgess <thade...@thadeusb.com> wrote: > > > Would blocks be too much to ask for? > > > > -Thadeus > > > > On Sun, Nov 22, 2009 at 9:15 AM, mdipierro <mdipie...@cs.depaul.edu> > > wrote: > > > > > Perhaps you are talking about something equivalent to Django blocks? > > > > We do not have that. > > > > We have other ways to do a similar thing. There are two basic things > > > > you can do: > > > > > 1) Extending > > > > #extedened.html > > > > <html><body>{{include}}</body></html> > > > > > #extending.html > > > > {{extends 'extended.html'}}<h1>Hello<h1> > > > > > 2) Including > > > > #including.html > > > > <html><body>{{include 'body.html'}}</body></html> > > > > > #body.html > > > > <h1>Hello<h1> > > > > > And you can mix and match. > > > > You can also pass functions to the extended function > > > > > Extending > > > > #extedened.html > > > > <html><body><h1>{{header()}}</h1>{{include}}<h1>{{footer()}}</h1></ > > > > body></html> > > > > > #extending.html > > > > {{def header():}}This is the header{{return}} > > > > {{def footer():}}This is the footer{{return}} > > > > {{extends 'extended.html'}}<h1>Hello<h1> > > > > > and you can do these things in a try ... except to have a default: > > > > > <html><body><h1>{{try: header()}}{{except:}}default{{pass}}</h1> > > > > {{include}}<h1>{{footer()}}</h1></body></html> > > > > > Massimo > > > > > On Nov 22, 7:18 am, jensmun <j...@acamedia.org> wrote: > > > > > Hi, > > > > > > Typical case of embarrassing situation. I don't know anything about > > > > > programming and wanted to try this out. Unfortunately I can't even > > get > > > > > my head around extensions of views. And I can't seem to find a > > > > > description of something this basic. > > > > > > I've tried stripped the example app in web2py from everything but a > > > > > default controller, two views and the db-model. But I can't get the > > > > > extension of views to work. And the Welcome-application is far too > > > > > complicated for somebody like me to understand. > > > > > > I would be grateful for a pointer to some place which explains view > > > > > and their extensions. If for example there are two places where I use > > > > > <h1> how does the extension view know which of these two replace with > > > > > the <h1> in the extension. > > > > > > Stupid question I know - but I've been trying to create a model and > > > > > extension view which changes top "Welcome customize me" and not been > > > > > succeeding. > > > > > > And Massimo's manual assumes a lot of this knowledge already I feel - > > > > > since the examples moves quickly past how extensions change the > > parent- > > > > > node. > > > > > > Grateful for any direction, > > > > > > Jens > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---