What's the best way to render a template by view/session?

While building my first app to learn elixir and phoenix framework, I’ve been learning how Coherence the auth package works and the thing it and an auth tutorial I’ve read - http://nithinbekal.com/posts/phoenix-authentication/ - have been teaching me the most about is view helpers, and how they are used to abstract common logic like creating links for when a user is logged in or not, which is checked for in the view, then renders the relevant link eg sign in /out.

As a noob, I want to ask the stupid question - if this is where such logic should go because it is mostly view related or is there a better place for it?

Yes, usually view related logic (Gravatar URL, guest_or_user link etc.) goes in the helpers, and views are used to write the HTML.

For example, for news feed, you can iterate through news item partial, and for localized content (ex. display the right currency or measurement) you can use helper function.

2 Likes

Thanks!