Search code examples
slim-lang

How can I add a property in the slim markup language?


I'd like to add a property to a tag generated by slim. For example:

<input type='text' name='name' required>

Solution

  • To create the HTML example you provided, your Slim would look like this:

     = text_field_tag :name, required: 'required'
    

    To add any additional attributes to the input tag, you'd simply provide additional arguments to the text_field_tag method. So if you wanted to specify the class attribute, you could do:

     = text_field_tag :name, required: 'required', class: 'really-nice-text-field'
    

    UPDATE:

    This would also work:

     = text_field_tag :name, required: true