bartblast
I encountered a strange problem related to view (custom) helper functions, and I’m out of ideas how to fix it…
I’ve got a LiveView:
lib/my_project_web/live/app/subdir/name.ex
in which I render a template with:
def render(assigns) do
Phoenix.View.render(MyProjectWeb.App.SubdirView, "name.html", assigns)
end
The module MyProjectWeb.App.SubdirView defines the following function:
def my_helper do
"test"
end
The template:
lib/my_project_web/templates/app/subdir/name.html.leex
tries to use the mentioned function with <%= my_helper() %>
But the following compilation error is thrown:
== Compilation error in file lib/my_project_web/views/app_view.ex ==
** (CompileError) lib/my_project_web/templates/app/subdir/name.html.leex:114: undefined function my_helper/0
(elixir 1.10.3) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
(stdlib 3.12.1) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir 1.10.3) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
It looks like the template is rendered in AppView context instead of SubdirView.
Has anybody encountered similar situation?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bartblast
Problem fixed:
I’ve had a pattern option specified in view setup, in lib/my_project_web.ex
Removing it, fixed the issue.