RejectedSoftware Forums

Sign up

diet Template simple layout question

When I have a loop to generate a table I want to write an Index with a dot (.) in the first row.

-foreach( i, row; rows) 
    tr
        td=(i+1)

How to get a "." behind the (i+1) nicely?
Not using something like

   td=format("%d",i+1)~"."

In jade there is a syntax, allowing more than one value in a line.

With

-foreach( i, row; rows) 
    tr
        td
            =(i+1)
            .

I get two additional div tags.

 ="#{i+1}."

Is not working outside a tag.
Any hint? Best regards mt.

Re: diet Template simple layout question

On Mon, 22 Feb 2016 16:41:38 GMT, Martin Tschierschke wrote:

When I have a loop to generate a table I want to write an Index with a dot (.) in the first row.

 -foreach( i, row; rows)
     tr
         td=(i+1)

How to get a "." behind the (i+1) nicely?

Normally, I'd use td #{i+1}.

Not using something like

td=format("%d",i+1)~"."

In jade there is a syntax, allowing more than one value in a line.

With

 -foreach( i, row; rows)
     tr
         td
             =(i+1)
             .

I get two additional div tags.

To avoid the div tags, you can use the text node operator |:

td
    |= i+1
    |.

  ="#{i+1}."

Same in this situation, just without the =:

td
    |#{i+1}.

Is not working outside a tag.
Any hint? Best regards mt.

The interpolations generally only work within quoted attribute values and within text nodes (either following a tag, or following the pipe |). Everything else is a normal D expression and behaves just like it would outside of a Diet template.