[Zope3-dev] Re: Better access to APIs in paths (was Re: needingviewsclues - template/title troubles)

John D. Heintz jheintz@isogen.com
25 Feb 2003 14:47:28 -0600


How do custom extensions get registered? I certainly would mind if some
namespace-things were pre-included, but what about "plone:" for example?

John

On Tue, 2003-02-25 at 14:42, Jim Fulton wrote:
> Shane Hathaway wrote:
> > Casey Duncan wrote:
> > 
> >> FWIW: Me Three.
> >>
> >> I have no inherent love for XML namespaces, but they are a widely 
> >> understood/documented concept that we can readily co-opt for this.
> >>
> >> Perhaps we could define some configurable default set of namespace 
> >> declarations made implicitly for all html page templates.
> >>
> >> <beat what="drum">Either that or get the code the hell out of the 
> >> templates all together... ;^)</beat>
> > 
> > 
> > Well, part of what this does is it lets you do many things in templates 
> > that formerly required Python expressions.  Currency formatting is just 
> > scratching the surface.
> > 
> > And before we say that presentation details like formatting currency 
> > should require a Python script, imagine the following hypothetical 
> > future exchange:
> > 
> > =======================================
> > 
> > [Newbie]
> > I just downloaded Zope today and it's really cool.  I made a little 
> > checkbook register using a page template.  It's way better than PHP. Now 
> > I can't figure out how to show only two digits after the decimal point.  
> > I don't know Python.  Can you help?
> > 
> > [Guru]
> > Hmm, you'll have to use some Python.  Don't use a Python expression, 
> > though, because that would be putting code in your template.  Write a 
> > script to do it.
> > 
> > [Newbie]
> > Can you help me write the script?
> > 
> > [Guru]
> > Ok, here you go:
> > 
> > from zope.app.servicenames import LocaleService
> > from zope.components import getService
> > def money(context, n):
> >   return getService(context, LocaleService).formatCurrency(n)
> > 
> > [Newbie]
> > Um, okay.  I made the script and I think it works.  Now how do I get my 
> > template to call it?
> > 
> > [Guru]
> > Oops, somehow you have to pass arguments to the script.  Dang.  Page 
> > templates don't provide a way to do that without Python expressions. 
> > You'll need a Python expression after all.  Try this (replace "value" 
> > with whatever variable you're using):
> > 
> > <span tal:content="python: container.money(container, value)">
> > $15.00
> > </span>
> > 
> > [Newbie]
> > That worked.  But it's going to take a long time to figure out that 
> > script you sent me.
> > 
> > =======================================
> > 
> > 
> > Now imagine this exchange:
> > 
> > 
> > =======================================
> > 
> > [Newbie]
> > I just downloaded Zope today and it's really cool.  I made a little 
> > checkbook register using a page template.  It's way better than PHP. Now 
> > I can't figure out how to show only two digits after the decimal point.  
> > I don't know Python.  Can you help?
> > 
> > [Guru]
> > Use the string formatting API.  Try this (replace "value" with whatever 
> > variable you're using):
> > 
> >   <div tal:namespaces="sf zope:string-fmt">
> >   <span tal:content="value/sf:money">$15.00</span>
> >   </div>
> > 
> > [Newbie]
> > Hey, neat, that makes sense.  But do I have to write "tal:namespaces" 
> > each time I use "sf:money"?
> > 
> > [Guru]
> > You can put tal:namespaces at the top of your template.  It applies to 
> > all contained elements.
> > 
> > [Newbie]
> > Oh, okay.  I guess that means I could write it this way too:
> > 
> >   <span tal:namespaces="sf zope:string-fmt"
> >     tal:content="value/sf:money">$15.00</span>
> > 
> > [Guru]
> > Yep.  I think I'll add a recipe to zopelabs.com.
> > 
> > [Newbie]
> > Don't bother, this is easy enough.  Thanks!
> > 
> > =======================================
> 
> Now, imagine this exchange:
> 
> [Newbie]
> I just downloaded Zope today and it's really cool.  I made a little
> checkbook register  using a page template.  It's way better than PHP. Now
> I can't figure out how to show only two digits after the decimal point.
> I don't know Python.  Can you help?
> 
> [Guru]
> Use the string formatting API.  Try this (replace "value" with whatever variable you're using):
> 
>    <span tal:content="value/sf:money">$15.00</span>
> 
> [Newbie]
> Hey, neat, that makes sense.
> 
> (feels like groundhog day)
> 
> > 
> > 'nuff said.
> 
> Yup. :)
> 
> I really don't think that the declaration adds anything but ceremony in your example.
> 
> Jim
> 
> 
> -- 
> Jim Fulton           mailto:jim@zope.com       Python Powered!
> CTO                  (888) 344-4332            http://www.python.org
> Zope Corporation     http://www.zope.com       http://www.zope.org
> 
> 
> _______________________________________________
> Zope3-dev mailing list
> Zope3-dev@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-dev
-- 
John D. Heintz | Senior Developer

1016 La Posada Dr. | Suite 240 | Austin TX 78752
T 512.380.0347 | jheintz at isogen.com

http://www.isogen.com