Viewing latest docs.
Switch version: v3

Generators

Generators

mix petal.gen.live

This produces the same files as Phoenix’s mix phx.gen.live (docs). The only difference is that the templates use Tailwind and Petal Components. You can try it out with:

mix petal.gen.live Todos Todo todos label:string is_done:boolean

ℹ️ Information: The default implementation uses the Table component and Streams. The following variation will generate an alternate template using the Data Table component (without Streams):

mix petal.gen.live Todos Todo todos label:string is_done:boolean --data-table

Add the routes from the output.

ℹ️ Information: If you're wondering where to put the routes, you can search in the router file for the text "Add live authenticated routes here", and add them straight after that line.

defmodule PetalProWeb.Router do
...
# App routes - for signed in and confirmed users only
scope "/app", PetalProWeb do
pipe_through [:browser, :authenticated]
...
live_session :authenticated,
on_mount: [
...
] do
# Add live authenticated routes here
live "/todos", TodoLive.Index, :index
live "/todos/new", TodoLive.Index, :new
live "/todos/:id/edit", TodoLive.Index, :edit
live "/todos/:id", TodoLive.Show, :show
live "/todos/:id/show/edit", TodoLive.Show, :edit
end
end
...
end

These live inside the /app scope, so your todos are at /app/todos.

After running the generator and adding the routes, you’ll have a fully functional CRUD interface: an index screen listing all todos, a form for creating new todos, and a show page for viewing individual records. All screens come pre-styled with Tailwind and Petal Components.

mix petal.gen.html

Same file output as phx.gen.html (docs), but the templates use Petal Components. It doesn’t add a Pro layout: each page starts with <.container> and renders inside the app’s default layout, with no sidebar. The sidebar <.layout> component renders LiveComponents (the sidebar’s notifications item with its unread badge), so it can’t wrap a controller page. If you want the pages in the signed-in sidebar, use petal.gen.live and wrap its templates in <.layout type="sidebar">.

Example:

mix petal.gen.html Todos Todo todos label:string is_done:boolean