# Basic View Helpers The [Jasper::Helpers](https://github.com/amberframework/jasper-helpers) library provides a common set of helper methods that can simplify the development of the views. ## Links A `link_to` helper is available: ```text == link_to "Home", "/" ``` Produces the following HTML ```markup Home ``` ## Buttons A `button_to` helper is available: ```text == button_to "Logout", "/logout" ``` Produces the following HTML ```markup
``` For more complex forms, see section below. ## Forms The form helpers listed below are very basic helpers that are included by default. For a more complete form building experience we strongly recommend using [FormBuilder.cr](form-builder.md) The following methods provide simple HTML form elements: * `form` * `text_field` * `label` * `hidden_field` * `select_field` * `text_area` * `check_box` * `submit` Use `amber generate scaffold [Resource] [field:type] ...` to get the most up-to-date examples of using helpers for resources. ### form ```text == form(action: "/posts", method: :post) do == csrf_tag == submit("Create Post") / When using `method: :patch`, it add the hidden '_method' field for you == form(action: "/posts", method: :patch) do == csrf_tag == submit("Update Post") ``` Produces the following HTML ```markup
``` ### text\_field ```text == text_field name: "title", value: "", placeholder: "Title" ``` Produces the following HTML ```markup ``` ### label ```text == label :title ``` Produces the following HTML ```markup ``` ### text\_area ```text == text_area name: "body", content: "", placeholder: "Body", size: "30x10" ``` Produces the following HTML ```markup ``` ### hidden\_field ```text == hidden_field name: "secret", content: "Super Secret" ``` Produces the following HTML ```markup ``` ### select\_field ```text / Array of Arrays == select_field name: "ranking", collection: [[1, "First"], [2, "Second"]], selected: 1 / Array of Hashes == select_field name: "ranking", collection: [{ 1 => "First" }, { 2 => "Second" }], selected: 1 / Hash == select_field name: "ranking", collection: { 1 => "First", 2 => "Second" }, selected: 1 ``` All the previous code samples produce the following HTML ```markup ``` ### check\_box ```text == check_box(:published, checked: false) ``` Produces the following HTML ```markup ``` ### All together ```text == form(action: "/posts", method: :post) do == csrf_tag == hidden_field name: "secret", content: "Super Secret" == label :title == text_field name: "title", value: "", placeholder: "Title" == label :body == text_area name: "body", content: "", placeholder: "Body", size: "30x10" == label :ranking == select_field name: "ranking", collection: [[1, "First"], [2, "Second"]], selected: 1 == label(:published) == check_box(:published, checked: false) == submit("Create Post") ``` Produces the following HTML ```markup
```