I have an html page and want to change navbar depending on the user’s role. I use http_reply_file and need to pass the role to html. What is the best way to do that?
P.S. I wouldn’t want to rewrite the code for reply_html_page.
I think it depends on ow you integrate the navbar into the page and how you decide on the user role. For the first, do you use the reply_html_page/3 and the Style argument? There are so many ways to decide on the user and user role I hardly know what to ask …
If you can decide on the role from the HTTP request and/or authorization library, you can just write a predicate that does so and make the predicate that generates the part of the page that must be changed dependent on that.
Next you can use reply_html_page/3 to deal with the navbar. Note that you can use HTML quasi quotations to include verbatim HTML into the Prolog source and pass parameters to it.
The docs of reply_html_page/3 explain the idea. user:body/2 allows wrapping the content that you create from the page generation. This allows adding headers, footers, scripts, etc. The Style argument is available to the hook, so it can use different wrappers for different parts of the website.