This is how a normal layout file look like, have and
In Phoenix, each page come along with
unique_view_name function can be defined in LayoutView
So for example when I go to root_path, which are in context
Page and action is
index, my body html would be
We got only one file
app.js that gonna be used in the layout file.
unique_view_name that we defined above.
per_pages folder will help us to auto-find the correct functions needed to run on a specific page.
per_pages folder with the
unique_view_page on each page.
Each file on per_pages folder must export default a function, so that it can be call
And finally the
With this, on every page, the function
handleDOMContentLoaded will run, which will do 2 things:
- run the
base_functions()this is basically the common functions that run on every page, like popover, tooltip, select2, datepicker, etc.
This solution will work not only in Phoenix, but also in Rails so similar frameworks. For Rails, we can use the
action_name to setup the
unique-view-name and other setups are just the same. Hope this could help someone who got same problems as I got.