Reputation: 51515
I read the documentation http://www.playframework.org/documentation/1.1/tags#ageta and I don't get it.
Can someone provide a better, easier to understand example ?
Upvotes: 3
Views: 261
Reputation: 37813
This is essentially a way to avoid copying and pasting a bunch of HTML repeatedly and then changing a dozen little details in it.
The starting example they give in the documentation (which I know you've read, but which I'l quote here for ease of reference) is this:
<p>
<label>&{'user.name'}</label>
<input type="text" id="user_name" name="user.name" value="${user?.name}" class="${errors.forKey('user.name') ? 'has_error' : ''}">
<span class="error">${errors.forKey('user.name')}</span>
</p>
If you imagine starting with that markup on your page and then adding a second field to the form, you'd have to copy/paste that entire block and then change &{'user.name'}
, user_name
, user.name
, ${user?.name}
, user.name
, and user.name
(each a separate reference to the same basic field) just to get the new markup to apply to your new field.
And that's just more typing than some of us are willing to undertake merely to add a field to a darn form.
The replacement #{field 'foo'}
allows is this:
#{field 'user.name'}
<p>
<label>&{field.name}</label>
<input type="text" id="${field.id}" name="${field.name}" value="${field.value}" class="${field.errorClass}">
<span class="error">${field.error}</span>
</p>
#{/}
The advantage here is that user.name
appears in exactly one place. If you were to copy/paste this markup to add another field, you'd have to make only one replacement: the one in the #{field ...}
tag.
The end result is that it's easier to develop standard markup for the many fields on your form without having to do a lot of error-prone manual replacement of the labels, names, IDs, current values, error messages, classes, et cetera.
Upvotes: 3