[plt-scheme] Conditions in web-templates

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Sat Feb 7 10:07:07 EST 2009

Yes. Here is an example:

if.html:
@(if (@monkeys . > . @monkey-limit)
     @list{<p>There are too many monkeys!</p>}
     @(if (@monkeys . < . @monkey-minimum)
             @list{<p>There aren't enough monkeys!</p>}
             @list{<p>There are just enough monkeys!</p>}))

http://svn.plt-scheme.org/plt/trunk/collects/tests/web-server/template/examples/if.html

run.ss:
(define (if-template #:monkeys monkeys
                     #:monkey-limit monkey-limit
                     #:monkey-minimum monkey-minimum)
  (include-template "if.html"))

(if-template #:monkeys 5
             #:monkey-limit 10
             #:monkey-minimum 2)
(if-template #:monkeys 11
             #:monkey-limit 10
             #:monkey-minimum 2)
(if-template #:monkeys 1
             #:monkey-limit 10
             #:monkey-minimum 2)

Jay

On Sat, Feb 7, 2009 at 7:47 AM, Max E. Kuznecov <syhpoon at syhpoon.name> wrote:
> Hi,
> I'm using plt web-server for my project.
> Content is rendered using web-server/templates module.
> I've got a questions about @-syntax:
> Is it possible to render a particular template branch using
> some condition as a criterion?
> I.e. I'd like to be able to write something of the kind:
>
> @if(expr){
>        branch1
> }
> {
>        else-branch
> }
>
> Thanks.
>
> --
> ~syhpoon
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.