Serving restricted and public page on the same location

What is the best practice to show a slightly different page on a golang website after a user sings in? Is it better put together both pages into one template if-else clause or should I make 2 different templates and execute the second one after login or are there better method for this?

How different is “slightly different”?

Actually, it isn’t really “slightly” all the time. So it depends on the page, but maybe the restricted part is about 5 paragraphs on random places in the html document.

This is mostly a judgement call. For things like a basic site layout and navbar you likely want to use the same template with a if/else on whether to show “sign in” or “my account” in the navbar. Most of the rest of that layout code won’t change much.

For the rest of the page you could go either route. Perhaps it makes sense to create two unique templates and do the if block in regular go code before executing the template. Or maybe you want to create two templates and do “if signed in {{template “x” .}} else {{template “y” .}}”

Without knowing more it is hard to give solid advice. There isn’t a single best way to go here.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.