Phoenix 1.7 and inversion of control to render a sidebar

marcin
Thu, 09 Mar 2023 21:46:07 +0000
Questions / Help

Hi!
I’m trying to have a layout in Phoenix 1.7, where besides @inner_content I also have a dynamic sidebar.

The content of the sidebar should depend on the view. How should I approach this? The last place where I can affect the sidebar is a controller I guess - i can set the assigns[:sidebar_content] and then read this in sidebar component.

However, it seems more elegant to set the sidebar content in the view – the controller assigns data, and the view decides how it is displayed in @inner_content and in the sidebar.
Is such inversion of control flow possible?

5 posts - 3 participants