I think it's mostly a matter of personal preference, but some people prefer
to use native HTML when it's in a view and the web2py helpers when it's in a
controller (or model). The helpers are also useful any time you need to do
any server side DOM parsing and manipulation (see
http://www.web2py.com/book/default/chapter/05#Server-side-DOM-and-Parsing).
Note, for building URLs, you should always use the URL() function (whether
in a view or a controller).
Anthony
On Sunday, July 10, 2011 4:10:46 PM UTC-4, (m) wrote:
> Newbie to Web programmer here. Please be gentle.
>
> I am trying to get my head around HTML helpers and see that they have
> been discussed so much and so often in this group that (1) I can't
> find what I'm looking for and (2) I am thinking there ought to be a
> sticky someplace that talks about their proper care and feeding.
>
> In particular, let's take the Image Blog example from The Book, file
> default/index.html:
>
> {{extend 'layout.html'}}
> <h1>Current Images</h1>
> <ul>{{=LI(A(image.title, _href=URL("show", args=image.id)))}}
> {{for image in images:}}
> {{=LI(A(image.title, _href=URL("show", args=image.id)))}}
> {{pass}}
> </ul>
>
> My first approach to writing this would have been to use native HTML
> as much as possible so as to make porting to or from templates as easy
> as possible. Also helps (me) with readability. Something like:
>
> {{extend 'layout.html'}}
> <h1>Current Images</h1>
> <ul>
> {{for image in images:}}
> <li><a href="{{=URL("show", args=image.id)}}">{{=image.title}}</a></
> li>
> {{pass}}
> </ul>
>
> This approach seems to work -- but I am wondering if there is an
> advantage to doing it with helpers that I am missing.