phoenix_components v1.0.3 PhoenixComponents.View View Source
This module provides a way to easily generate helper functions to render components.
The module can be included by others Phoenix.View modules to import components easily.
Example
When working on a project with several components you can use this module in your web/web.ex
definition.
defmodule MyApp.Web do
#...
def view do
quote do
use Phoenix.View, root: "web/templates"
use PhoenixComponents.View
# ...
end
end
end
After you include the module you can use the following helpers
defmodule MyApp.UserView do
use MyApp.Web, :view
import_component [:button, :jumbotron]
end
After you import a component into the view module you can use the component as follows
<div>
<%= button type: :primary do %>
Submit
<% end %>
</div>
Alternatively, you can also render a component without importing it by using the helper function component
.
<div>
<%= component :button, type: :primary do %>
Submit
<% end %>
</div>
Link to this section Summary
Functions
Helper to render a component by name
Helper to render a component by name and a list of attributes
Helper to render a component by name and a list of attributes
Macro to generate helpers for components inside views
Link to this section Functions
Helper to render a component by name.
## Example
<%= component :button %>
Helper to render a component by name and a list of attributes.
Note that attributes are available in the template as the map @attrs.
## Example
<%= component :button, color: "red", size: "small", label: "Submit" %>
Helper to render a component by name and a list of attributes.
Note that attributes are available in the template as the map @attrs.
## Example
<%= component :button, color: "red", size: "small" do %>
Submit
<% end %>
Macro to generate helpers for components inside views.
## Example
import_components [:button, :jumbotron]
Then you can use the component directly
<%= button type: "submit" %>