Phoenix.HTML.Link
Conveniences for working with links and URLs in HTML.
Summary↑
button(text, opts) | Generates a button that uses a regular HTML form to submit to the given URL |
link(text, opts) | Generates a link to the given URL |
Functions
Generates a button that uses a regular HTML form to submit to the given URL.
Useful to ensure that links that change data are not triggered by search engines and other spidering software.
Examples
button("hello", to: "/world")
#=> <form action="/world" class="button" method="post">
<input name="_csrf_token" value=""><input type="submit" value="hello">
</form>
button("hello", to: "/world", method: "get", class: "btn")
#=> <form action="/world" class="btn" method="post">
<input type="submit" value="hello">
</form>
Options
:to
- the page to link to. This option is required:method
- the method to use with the button. Defaults to :post.:form
- the options for the form. Defaults to[class: "button", enforce_utf8: false]
All other options are forwarded to the underlying button input.
Generates a link to the given URL.
Examples
link("hello", to: "/world")
#=> <a href="/world">hello</a>
link("<hello>", to: "/world")
#=> <a href="/world"><hello></a>
link("<hello>", to: "/world", class: "btn")
#=> <a class="btn" href="/world"><hello></a>
# You can use a `do ... end` block too:
link to: "/hello" do
"world"
end
Options
:to
- the page to link to. This option is required:method
- the method to use with the link. In case the method is not:get
, the link is generated inside the form which sets the proper information. In order to submit the form, JavaScript must be enabled:form
- customize the underlying form when the method is not:get
All other options are forwarded to the underlying <a>
tag.