PhoenixKitWeb.Components.LayoutWrapper (phoenix_kit v1.7.38)

Copy Markdown View Source

Dynamic layout wrapper component for Phoenix v1.7- and v1.8+ compatibility.

This component automatically detects the Phoenix version and layout configuration to provide seamless integration with parent applications while maintaining backward compatibility.

Usage

Replace direct layout calls with the wrapper:

<%!-- OLD (Phoenix v1.7-) --%>
<%!-- Templates relied on router-level layout config --%>

<%!-- NEW (Phoenix v1.8+) --%>
<PhoenixKitWeb.Components.LayoutWrapper.app_layout flash={@flash}>
  <%!-- content --%>
</PhoenixKitWeb.Components.LayoutWrapper.app_layout>

Configuration

Configure parent layout in config.exs:

config :phoenix_kit,
  layout: {MyAppWeb.Layouts, :app}

Summary

Functions

app_layout(assigns)

Renders content with the appropriate layout based on configuration and Phoenix version.

Automatically handles:

  • Phoenix v1.8+ function component layouts
  • Phoenix v1.7- legacy layout configuration
  • Fallback to PhoenixKit layouts when no parent configured
  • Parent layout compatibility with PhoenixKit assigns

Attributes

  • flash - Flash messages (required)
  • phoenix_kit_current_scope - Current authentication scope (optional)
  • phoenix_kit_current_user - Current user (optional, for backwards compatibility)

Inner Block

  • inner_block - Content to render within the layout

Attributes

  • flash (:map) - Defaults to %{}.
  • phoenix_kit_current_scope (:any) - Defaults to nil.
  • phoenix_kit_current_user (:any) - Defaults to nil.
  • page_title (:string) - Defaults to nil.
  • current_path (:string) - Defaults to nil.
  • inner_content (:string) - Defaults to nil.
  • project_title (:string) - Defaults to "PhoenixKit".
  • current_locale (:string) - Defaults to nil.

Slots

  • inner_block

build_locale_url(current_path, base_code)

generate_language_switch_url(current_path, new_locale)

get_language_flag(code)