Does the indentation in the templator matters as it in Python?

33 views
Skip to first unread message

Makto

unread,
Apr 18, 2012, 11:37:59 PM4/18/12
to we...@googlegroups.com
I saw the example in the web.py documentation:

Here is a simple template:
$def with (name)
Hello $name!


There's no indentation and even colon, which I'm familiar in Python, in the first line.
Is this format designed to be and required?
Or both are OK?

Anand Chitipothu

unread,
Apr 19, 2012, 12:30:31 AM4/19/12
to we...@googlegroups.com
Yes.
 
Or both are OK?

No.


Makto

unread,
Apr 19, 2012, 12:39:26 AM4/19/12
to we...@googlegroups.com
Thanks:)
But I saw some different codes on the same page:

Another example:
$def tr(values):
    <tr>
    $for v in values:
        <td>$v</td>
    </tr>

$def table(rows):
    <table>
    $for row in rows:
        $:row
    </table>

Here, colon and indentation are used.
I'm confused.
Of course, the best way to solve this is to test it myself....
I just hope the confusion could remind our guys of the ambiguity of the documentation.

在 2012年4月19日星期四UTC+8下午12时30分31秒,Anand写道:

Anand Chitipothu

unread,
Apr 19, 2012, 1:29:21 AM4/19/12
to we...@googlegroups.com
On Thu, Apr 19, 2012 at 10:09 AM, Makto <zhon...@gmail.com> wrote:
Thanks:)
But I saw some different codes on the same page:

Another example:

$def tr(values):
    <tr>
    $for v in values:
        <td>$v</td>
    </tr>

$def table(rows):
    <table>
    $for row in rows:
        $:row
    </table>

Here, colon and indentation are used.
I'm confused.
Of course, the best way to solve this is to test it myself....
I just hope the confusion could remind our guys of the ambiguity of the documentation.

The "$def with" at the beginning of template is a special case without colon and no indentation. Except that everything else looks very much like Python.

Anand

Makto

unread,
Apr 19, 2012, 3:18:37 AM4/19/12
to we...@googlegroups.com
Got it!
Can we treat the "def with (v1, v2, ...)" as a declaration of all the variables(v1, v2...) that will be used in the template?

在 2012年4月19日星期四UTC+8下午1时29分21秒,Anand写道:

Anand Chitipothu

unread,
Apr 19, 2012, 3:34:17 AM4/19/12
to we...@googlegroups.com
On Thu, Apr 19, 2012 at 12:48 PM, Makto <zhon...@gmail.com> wrote:
Got it!
Can we treat the "def with (v1, v2, ...)" as a declaration of all the variables(v1, v2...) that will be used in the template?

Yes, but it is more than that.

You can say:

$def with (v1, v2, v3="foo")

or

$def with (v1, v2, **kwargs)

etc.

The first form is commonly used, but the latter one is rarely used.

Anand

Makto

unread,
Apr 19, 2012, 4:04:00 AM4/19/12
to we...@googlegroups.com
Wow~many thanks!
The official documentation just has so much things uncovered ==

在 2012年4月19日星期四UTC+8下午3时34分17秒,Anand写道:
Reply all
Reply to author
Forward
0 new messages