Edgewall Software

Opened 17 years ago

Last modified 14 years ago

#134 reopened enhancement

#else support in #if directive

Reported by: Marcin.Kasperski@… Owned by: cmlenz
Priority: major Milestone:
Component: Template processing Version: 0.4.2
Keywords: Cc:

Description

Well, implementing #if without #else seems to be omission, isn't it?

Change History (7)

comment:1 Changed 17 years ago by cmlenz

  • Milestone 0.5 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

That's due to the text directives being the same as those in markup templates, and markup templates use choose/when/otherwise instead of if/else, basically because we need a single container element to put the multiple condition branches in.

So choose/when/otherwise is what you'd currently use instead of if/else. I don't think I'd want to change this unless we can also find a way to change it in markup templates.

I'm setting this to wontfix, but if you have an idea for implementing this in both markup and text templates, and can provide a patch, feel free to reopen.

comment:2 Changed 17 years ago by Marcin.Kasperski@…

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Well, compare

#if n There are ${n} items. #else Nothing found! #endif

to

#choose #when n > 0 There are ${n} items. #end #otherwise Nothing found! #end #end

(let's leave for now linebreaks introduced by the latter solution)

and you will find why this issue makes sense...

I am in no way genshi expert, just took a look at it as I am considering adding some web pages to the textual (so far) app - so I do not feel able to offer patches. But this simple example made me abandon the idea of using genshi for text templates.

Maybe instead of fighting this, genshi should just specify some way of translating HTML or XML templates into bare text (so I would write HTML or XML even when I would want to create simple text output). I do not know.

comment:3 Changed 17 years ago by anonymous

Hmm, I forgot about wiki markup. Once more:

if n
There are ${n} items. 
#else
Nothing found!
#endif
#choose
#when n > 0 
There are ${n} items. 
#end 
#otherwise 
Nothing found! 
#end 
#end

comment:4 Changed 17 years ago by anonymous

BTW, there is no reason why text parser couldn't map if/else/end onto internal choose/when/otherwise....

comment:5 Changed 16 years ago by cmlenz

  • Component changed from General to Template processing

comment:6 Changed 16 years ago by cmlenz

#208 has been marked as duplicate of this ticket.

comment:7 Changed 14 years ago by Carsten Klein <carsten.klein@…>

Perhaps, transforming the if...then elif then...else statement to a choose...when...end...otherwise...end statement would do the trick?

So, upon finding the if, the generator would yield first a choose and then a when, now, when finding the else, it would yield an otherwise, else, there was no else and so it will simply close the directive.

<py:if test="...">
 ...
</py:if>
<py:else>
 ...
</py:else>

would then be transformed to

<py:choose ...>
  <py:when test="...">
    ...
  </py:when>
  <py:otherwise>
    ...
  </py:otherwise>
</py:choose>
Note: See TracTickets for help on using tickets.