Imagine you have this existing directory
user
│
└───admin
│ admin.html.heex
│ employee.html.heex
└───customer
│ admin.html.heex
│ employee.html.heex
In the previous version using Phoenix.View
, we can simply render templates with similar names by differentiating them using path for example:
render UserView, "admin/admin.html.heex"
render UserView, "customer/admin.html.heex"
But now when we migrate them to Phoenix.Component, we will now rely on using embed templates like so:
embed_templates "users/**/*"
Embed templates convert templates to functional components using their filename as the function name. But since the path will be disregarded when embedding templates we will now have two admin components and two employee components. The compiler will warn us with a message similar to this:
warning: this clause for admin/1 cannot match because a previous clause at line 2 always matches lib/my_web/views/users/admin.html.heex:2
How do we handle this case? Does Phoenix intentionally design it like this so we will be forced to write a specific module to handle sub-templates for clearer context? For example, instead of UserView, we should now have User.AdminView and User.CustomerView?