understood.... I was arguing that having something like {{exterior_finish(car) }} is not any different than {{ car | pime | paint | bake | add_trim }} that is - where the code sits...
But in the cases you meant, yes - {{my()}} <static stuff> {{is_nicer_all_here()}} Thanks. As for multilne code: write "normal" code, encapsulted in {{ }}; for output, leave left side "blank" (dumps on template, so: {{=my_result(on_this)}} For starters, everywhere you would have "unindent" situation in python, in template put {{ pass }}; Actually you only need where it would be ambiguous, but for starters, that's a good rule - after you have code working, try removing the "pass"s you think are not necessary.... won't take long to see where you don't need them. For HTML helpers, they take all (?) the (optional) parameters that the W3C defines for the HTML equivalents. For examples, get the appliances (e.g. KPAX, others on the "Repository of free apps" link at web2py.com) On Oct 12, 5:13 pm, pigmej <[EMAIL PROTECTED]> wrote: > Now I see that I can make with web2py templates almost everything :). > > Massimo, I really think, You should add this recipes to howto :) > > @yarko: > > sometimes there is no staight way to modify something in controller. > But ok, I modify it, and then i loop them again in template -> so > there are two loops. One more than using filter in template ;) > > How to write multiline python code in filter ?? I cannot find real > example for this momemt... > > but maybe, replacing something in part of list/dictionary etc. > > On 12 Paź, 23:49, yarko <[EMAIL PROTECTED]> wrote: > > > This looks like only a stylistic discussion to me.... > > > Django has this too, and Jinja you say have a "shell like" syntax of > > "pipes" --- that is output of one operation feeds input of another. > > n > > {{ car | prime | paint }} is equivalent to {{ paint(prime(car)) }}, > > or for that matter {{ car.paint().prime() }} > > > Functionally, I don't see anything you can do one way over the > > other..... it's a matter of style, convenience, what your used to, > > what you like reading. > > > I like the "pipeline" syntax, but I learned on UNIX in the mid-70's, > > so it's almost "genetic" for me to just read that. The downside to > > that is that you can get lulled into putting too much processing in > > the template ... precisely because it's so readable. > > > Having a utility function in a module, or a application local function > > in a controller is - as you say - doable. > > > But the more worthwhile thing is thinking about what you want to do, > > and putting it in a good place. And making the template as concise > > as makes sense. > > > re: one loop more on contoller side - not sure I follow you on that. > > Wherever you write the filters, they are running (in these examples) > > on the server, applied similarly, and when they are done, the > > resulting output is rendered into something sent out over the > > network... You could look at how many "calls" you have when snippets > > are in the template vs. explicitly defined utility functions, but I > > think this is more about the patterns of code maintenance (and > > reading) than anything... > > > I think it probably would not be hard to apply a transform to > > templates so that you can pile up calls with the "pipeline" flavor of > > showing transfer of control. But, other than end user reading - and > > what it might encourage about development steps - I don't think it > > materially changes anything. > > > Am I missing something? > > > Kind regards, > > Yarko > > > On Oct 12, 4:30 pm, pigmej <[EMAIL PROTECTED]> wrote > > > > massimo, > > > > filters... ok but what if I need to make more operations with strings > > > etc, python operations, imports, parsing something ? > > > More lines of code. > > > > For example I need to operate on dictionaries ( defining new, parsing > > > etc ) > > > > Theoretically, I can apply filters on controller side... but then > > > there is one ( or more ) loop more. > > > > On 12 Paź, 23:01, mdipierro <[EMAIL PROTECTED]> wrote: > > > > > You can do both: > > > > > 1) Example of passing variables to parent. > > > > Here is layout.html > > > > > <html><body><h1>{{=title}}</h1><p>{{include}}</p></body></html> > > > > > and here is an example of index.html > > > > > {{title='something'}} > > > > {{extend 'layout.html'}} > > > > Hello World > > > > > Also are variables returned by the action and defined in models are > > > > also passed to the parent. > > > > > 2) Example of a filter. > > > > You cannot filter HTML (because it does not make sense since you write > > > > it) but you can filter TEXT (coming from a variable for example) and > > > > the output of helpers. For example the following filter replaces > > > > newlines with <br />, sanitize everything else and wraps everything in > > > > a <p>. > > > > > {{def myfilter(s):}} > > > > <p>{{=XML(str(s).replace('\n','<br />),sanitize=False)}}</p> > > > > {{return}} > > > > > {{=myfilter("""Any<span>html code that > > > > you</span> like.""") > > > > {{=myfilter(H1(SPAN('Hello\nWorld')))}} > > > > > Massimo > > > > > On Oct 12, 3:42 pm, pigmej <[EMAIL PROTECTED]> wrote: > > > > > > thanks for reply. > > > > > > Python is templating engine - thats really good. > > > > > > But I can only include file in one place and there is no way to change > > > > > anything in parrent file. That's a minus, and the minor problem for > > > > > mine. > > > > > > The same thing with filters/macros. I need to use the same macro/ > > > > > filter in many files. I cannot find this "option" in web2py > > > > > templates... > > > > > > On 12 Paź, 22:11, yarko <[EMAIL PROTECTED]> wrote: > > > > > > > Also - if you want to use Genshi Templates (or try to do something > > > > > > similar for Jinja2), see the Genshi4web2py.py file and instructions > > > > > > here: > > > > > > >http://mdp.cti.depaul.edu/AlterEgo/default/show/162 > > > > > > > On Oct 12, 2:59 pm, yarko <[EMAIL PROTECTED]> wrote: > > > > > > > > There have been several discussions on this list on the topic - > > > > > > > for > > > > > > > example, look > > > > > > > throughhttp://groups.google.com/group/web2py/browse_thread/thread/1ef4eea826... > > > > > > > > I think a raesonable summary is: > > > > > > > > - web2py's templating, being very close to just being Python, is > > > > > > > likely to continue to be default for some time; > > > > > > > - some people have written tools to convert skins for other > > > > > > > templates > > > > > > > to convert to web2py, so if it's available graphic designs you > > > > > > > want, > > > > > > > that's one way to go > > > > > > > - there has been talk about still allowing an interface for other > > > > > > > engines. > > > > > > > > I think interest (beyond one of discussion) has not been strong > > > > > > > enough > > > > > > > for someone to identify all the core web2py things that would > > > > > > > have to > > > > > > > be moved into a module, and rewritten for another template engine. > > > > > > > This has spurned talk and work about modules for web2py, T2 > > > > > > > being one > > > > > > > example. It has not yet spurned a design analysis of where all > > > > > > > the > > > > > > > boundaries are, and what it would take to implement that. > > > > > > > > As for documentation, there's Chapter 5 of the web2py book... but > > > > > > > basically, the template language is python, the helper functions > > > > > > > are > > > > > > > named after HTML, so you can discover them and use them as you > > > > > > > would > > > > > > > expect (<h2>This Heading</h2> ==> H2('This Heading') ) with all > > > > > > > the > > > > > > > named paramteres that w3c defines to h2 (for example) mirrored in > > > > > > > H2(). There is a genshi translator (search these forums) and > > > > > > > there > > > > > > > is also Massimo's quick demonstraton of a layout builder - see the > > > > > > > link onhttp://www.web2py.com. The builder has a link on it to > > > > > > > download the result of your layout experimentation. > > > > > > > > Those are probably good starting places. > > > > > > > > Hope this was helpful. > > > > > > > > Regards, > > > > > > > Yarko > > > > > > > > On Oct 12, 2:27 pm, pigmej <[EMAIL PROTECTED]> wrote: > > > > > > > > > Is there any way to change default template engine in web2py? > > > > > > > > > I would like to change it to something better with more > > > > > > > > features like > > > > > > > > Jinja2 > > > > > > > > > Or maybe there is a lot of undocumented things in default > > > > > > > > template > > > > > > > > engine ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---