Created
March 9, 2021 18:17
-
-
Save mhanberg/c564703fa31a91464ad948e0dd846269 to your computer and use it in GitHub Desktop.
Using Temple directly in live view modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/my_app/views/live_view.ex | |
defmodule MyAppWeb.LiveView do | |
defmacro render(block) do | |
quote do | |
def render(var!(assigns)) do | |
require Temple | |
Temple.compile(unquote(Phoenix.LiveView.Engine), unquote(block)) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/my_app_web.ex | |
defmodule MyAppWeb do | |
# ... | |
def live_view do | |
quote do | |
use Phoenix.LiveView, | |
layout: {MyAppWeb.LayoutView, "live.html"} | |
import MyAppWeb.LiveView | |
unquote(view_helpers()) | |
end | |
end | |
def live_component do | |
quote do | |
use Phoenix.LiveComponent | |
import MyAppWeb.LiveView | |
unquote(view_helpers()) | |
end | |
end | |
# ... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/my_app_web/live/page/show.ex | |
defmodule MyAppWeb.Page.Show do | |
use MyAppWeb, :live_view | |
render do | |
div do | |
"Hello, world!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment