Re: [Zope] Surpress white space?
OdesÃlatel: Sergey Volobuev <zope@phpv.khv.ru>
Is there an easy way to surpress all whitespace output from DTML? Essentially, I have a situation where DTML is used for a crutch to do some simple logical things, but where most of the interesting stuff happens in external methods. There are a few lines of DTML that actually produce useful output, but I am getting a TON of whitespace before my interesting output that I need to surpress.
I also trying to solve this problem and the only way i've found is avoid whitespace between dtml tags. Like this:
<dtml-in xxx><dtml-if comecondition><dtml-var somevariable></dtml-if></dtml-in>
Of course, this is ugly solution because it makes code almost unreadable :(
Better solution: <dtml-in rev
<dtml-with sequence-item ><a href="<dtml-var absolute_url>/" class="navipath"><dtml-var title_or_id></a </dtml-with <dtml-if sequence-end ><br> <dtml-else> , </dtml-if </dtml-in>
Regards, JL.
Better solution:
<dtml-in rev
<dtml-with sequence-item <a href="<dtml-var absolute_url>/" class="navipath"><dtml-var title_or_id></a </dtml-with <dtml-if sequence-end ><br> <dtml-else> , </dtml-if
</dtml-in>
But it is still ugly :((
On Wednesday 09 July 2003 15:37, Sergey Volobuev wrote:
But it is still ugly :((
Soon after I started using Zope, I created a <dtml-unitws> tag that replaces blocks of whitespace with a single character. The code looks a little dated, but is still functional. Examle usage below, followed by code. I hope this helps. <dtml-unitws> <dtml-in xxx> <dtml-if comecondition> <dtml-var somevariable> </dtml-if> </dtml-in> </dtml-unitws> from string import split, strip, join, replace import DocumentTemplate.DT_Util from DocumentTemplate.DT_String import String class UnitWhitespaceTag: """ Removes redundant whitespace (not very conservatively) """ name='zcunitws' blockContinuations=() def __init__(self, blocks): tname, args, section = blocks[0] args = DocumentTemplate.DT_Util.parse_params(args) self.blocks = section.blocks def render(self,md): a = [] for line in split(DocumentTemplate.DT_Util.render_blocks(self.blocks, md),'\n'): line = strip(line) if line: b = [] for word in split(line,' '): b.append(strip(word)) a.append(join(b,' ')) return join(a,'\n') __call__=render String.commands['unitws']=UnitWhitespaceTag -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
participants (3)
-
Jaroslav Lukesh -
Sergey Volobuev -
Toby Dickenson