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?