Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the field tag in a user defined tag with the Play! Framework?

Right now I have a view like this that works.

#{form @UserCreate.create()}
    #{field 'user.email'}
        #{text field /}
    #{/field}
#{/form}

With a corresponding text tag defined which then uses the field (it is more complicated than this, just boiling down to essentials)

<input type="text" id="${_arg.id}" name="${_arg.name}" value="${_arg.value}">

Ideally I would rather have it so I did not have to declare the field in the view so it would look like this.

#{form @UserCreate.create()}
    #{text 'user.email' /}
#{/form}

With a tag that looks like this.

#{field 'user.email'}
    <input type="text" id="${field.id}" name="${field.name}" value="${field.value}">
#{/field}

But the field.value always returns null because user is not in the tags' template binding. I am not really sure how to approach things at this point. Suggestions?

like image 663
Ransom Briggs Avatar asked Nov 14 '22 17:11

Ransom Briggs


1 Answers

Hey I have an interesting workaround: Just write the first line of the custom tag

 %{user = _user}%  
 #{field 'user.email'}  
    <input type="text" id="${field.id}" name="${field.name}" value="${field.value}">    
 #{/field} 

This works for me :)

like image 128
Ahmed Saleh Avatar answered May 26 '23 02:05

Ahmed Saleh