On Tue, Oct 5, 2010 at 10:17 PM, Matt H <matt2...@gmail.com> wrote:
> How would I go about removing whitespace from the html output of my
> mako templates? I see that in the /data/templates directory the
> templates are cached with a ton of whitespace, so how would I execute
> a function on the output before it gets cached by Mako?

You may get better responses on the Mako list rather than Pylons,
but without further details I suspect there are a couple things you
may want to do.

First, when you write your templates be aware of where you may
be inadvertently introducing whitespace. Make use of the end-of-line
backslash syntax to suppress extra line breaks, especially when
ending a Mako block.  Rather than

Some text
<%
   some python code
%>
more text.

Do something like this:

Some text\
<%
  some python code
%>\
more text.

Also don't insert unnecessary blank lines if you don't need them,
instead just insert a blank Mako comment line:   ##


Secondly, if you want to remove some whitespace by passing the
output through a function prior to caching you may want to use
Mako's filter mechanism. It already has a built-in filter to strip
whitespace at the beginning and end. If you want something more
sophisticated you can provide your own filtering function. Read up
on Mako's filters:

http://www.makotemplates.org/docs/filtering.html

If you have a more specific example that may help to answer
your question.
-- 
Deron Meranda
http://deron.meranda.us/

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-disc...@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to