phoenixframework / phoenix_view Goto Github PK
View Code? Open in Web Editor NEWView abstraction for Phoenix v1.0-v1.6
License: MIT License
View abstraction for Phoenix v1.0-v1.6
License: MIT License
I noticed that when we call render_one/4
or render_many/4
with the :as
option it gets passed down to render
.
Is this intentional? If not, would you welcome a PR to remove it?
Example:
render_many([user], MyApp.UserView, "data.text", as: :data)
Diff to quickly reproduce with the tests of this repo:
diff --git a/test/fixtures/views.exs b/test/fixtures/views.exs
index 1cec333..b8302f4 100644
--- a/test/fixtures/views.exs
+++ b/test/fixtures/views.exs
@@ -44,7 +44,8 @@ defmodule MyApp.UserView do
"show user: " <> user.name
end
- def render("data.text", %{data: data}) do
+ def render("data.text", %{data: data} = some) do
+ IO.inspect(some)
"show data: " <> data.name
end
It prints:
%{as: :data, data: %MyApp.User{name: "name"}}
# ^--- wasn't expecting to see an :as key here
I'm trying to migrate a Phoenix.View to Phoenix.Component as described in the migration guide.
A small obstacle is that the guide says embed_template "../templates/my"
but the correct code seems to be embed_templates "../templates/my/*"
.
The larger obstacle is that Phoenix.Controller.render/3
breaks because MyAppWeb.MyView.render/2
is undefined, and the guide doesn't offer any way to resolve this problem. The guide should explain what to do to handle this.
Elixir 1.12.2 - OTP 24
phoenix 1.6.6
phoenix_view 1.1.0
ArchLinux 5.15.7-arch1-1
Phoenix.View.render_to_string/3
fails when template filename does not have .html.(h)eex
extension with the following stacktrace:
** (ArgumentError) errors were found at the given arguments:
* 1st argument: not an iodata term
:erlang.iolist_to_binary({:safe, ["Hello from TEXT\n"]})
(phoenix_view 1.1.0) lib/phoenix/view.ex:480: Phoenix.View.render_to_string/3
This behavior is consistent whether I use template files or define render methods directly in view module.
defmodule SomeAppWeb.EmailView do
@moduledoc """
Email view
"""
use SomeAppWeb, :view
# WORKS!
# iex > Phoenix.View.render(SomeAppWeb.EmailView, "contact_form.html", %{})
# "Hello from HTML\n"
def render("contact_form.html", assigns) do
~H"""
Hello from HTML
"""
end
# DOES NOT WORK!
# iex > Phoenix.View.render(SomeAppWeb.EmailView, "contact_form.text", %{})
# ** (ArgumentError) errors were found at the given arguments:
#
# * 1st argument: not an iodata term
#
# :erlang.iolist_to_binary({:safe, ["Hello from TEXT\n"]})
# (phoenix_view 1.1.0) lib/phoenix/view.ex:480: Phoenix.View.render_to_string/3
def render("contact_form.text", assigns) do
~H"""
Hello from TEXT
"""
end
end
Phoenix.View.render_to_string/3
should render heex
regardless of the extension.
๐ Thanks for all your work, from investigating the changes in version 2 I noticed that there is no changelog entry, it'd be great if there could be one put together with all the changes, it'd also be nice if there was a seperate pulled out upgrade guide for the docs, so its easy to find the info on how to upgrade from 1.x to 2.x.
Phoenix 1.6.2
PhoenixLiveView 0.17.1
Elixir 1.12.3
MacOS 11
Provided a gist for reference at the bottom.
Template is rendering incorrectly. It's duplicating lines instead.
If I run this multiple time I get duplication repeating at different places rather than the actual render call rendering the specific file reference. It seems to happen on gettext
calls.
The bread crumbs work in different places throughout the project, for some reason this specific location is broken.
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
<%= render(AdminWeb.BreadcrumbsView, "view.html", %{conn: @conn, breadcrumbs: breadcrumbs}) %>
This is part of what gets rendered:
Draft Details
<span class="badge badge-warning" style="float:right;">
Draft
</span>
Name
value="Form 1"
Schema
<br><br>
<form action="/team/Bf41mGmPuIGOwl4y/draft/update/zxrZ3U4UFNCWBom5" method="post"><input name="_csrf_token" type="hidden" value="BhkEJzJSDgoFDhYIOExDLB0lBD0jEwInuXwux3JbpGsxVxskwiBlpXEt">
<h2>
Draft Details
<span class="badge badge-warning" style="float:right;">
Draft
</span>
</h2>
<br>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<th>Name</th>
<td><input type="text" name="data[draft][name]" value="Form 1" class='form-control'></td>
</tr>
<tr>
<th>Schema</th>
<td>
<textarea rows="10" name="data[draft][schema]" class='form-control'>
redacted
</textarea>
</td>
</tr>
</tbody>
</table>
</div>
This initial piece
Draft Details
<span class="badge badge-warning" style="float:right;">
Draft
</span>
Name
value="Form 1"
Schema
should be what's written in the breadcrumbs
file shown in the gist.
The code that's supposed to be rendered gets executed, rendered, and placed in the right location.
https://gist.github.com/k-cross/3f8eaf7f5d9e40e78b2b025a47f8cc76
Thank you for the project and your help! Let me know if there's anything else I can do to provide context.
I am reviewing the docs for the Phoenix guide, and I would like to link to the docs.
Is there any planned release in the near feature?
If note I can leave an internal note and update later the docs when the first version of this library is published.
Thank you.
After these changes: v1.1.0...v1.1.1
Dialyzer started complaining that template_not_found/2
has no local return:
lib/namespace_web/views/error_view.ex:2:no_return
Function template_not_found/2 has no local return.
________________________________________________________________________________
lib/namespace_web/views/layout_view.ex:2:no_return
Function template_not_found/2 has no local return.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2
It complains about this method for every single :view
file.
Should we add this method to all view files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.