I’m building my first Phoenix app and need a little guidance.
Say I build a quiz maker.
- Admin users may create questions and answers;
- Visitors of the website can answer the questions.
I ran the following command to create my first context:
mix phx.gen.html Quiz Question questions text:string
But what confuses me, is that I will have two clearly distinct sections of my website, with two different layouts: a layout and templates for admins, and a layout and templates for the visitors.
Most of these generated files such as the templates to list the questions, create/edit/delete a question, and so on should only be accessible by an admin user.
Also, the template to view a question show.html.eex will be different for an admin and a visitor: the visitor will have a nicely displayed question (with different html), while the admin will have a rather raw template, using the same layout as the layout used for listing questions and editing questions.
All of the admin templates will have a basic layout, while the templates for the visitors will have a layout with a nicer design.
The command above generates for exemple:
lib/quiz_maker_web/templates/question/show.html.eex
lib/quiz_maker_web/templates/question/form.html.eex
...
While I need something like:
lib/quiz_maker_web/templates/admin/question/show.html.eex
lib/quiz_maker_web/templates/admin/question/form.html.eex
lib/quiz_maker_web/templates/guest/question/show.html.eex
...
I think my requirement is a pretty basic one, but I don’t know the best way to achieve it. Any help is very much appreciated!






















