Replies: 2 comments
-
I ended up doing the following: class ConsultingLayout < ApplicationLayout
def template(&)
render LayoutComponent.new(
theme: "dark",
header: "consulting/header",
meta_tags: {},
&
)
end
end
# NOTE: Base class needs to be a phlex rails layout to work
class ApplicationLayout < ApplicationView
include Phlex::Rails::Layout
end
class LayoutComponent < ApplicationView
include Phlex::Rails::Layout
include Phlex::Rails::Helpers::CSPMetaTag
include Phlex::Rails::Helpers::ContentFor
include Phlex::Rails::Helpers::CSRFMetaTags
include Phlex::Rails::Helpers::JavaScriptImportMapTags
include Phlex::Rails::Helpers::Routes
include Phlex::Rails::Helpers::StyleSheetLinkTag
def initialize(theme:, header:, meta_tags: {})
@theme = theme
@header = header
@meta_tags = meta_tags
super()
end
def template(&block)
doctype
html(data: { theme: @theme }, class: "min-h-full h-full min-w-full w-full mx-0 my-0 text-base antialiased") do
head do
meta(name: "viewport", content: "width=device-width, initial-scale=1, user-scalable=no")
meta(name: "view-transition", content: "same-origin")
meta(name: "apple-mobile-web-app-capable", content: "yes")
csrf_meta_tags
csp_meta_tag
stylesheet_link_tag "application", data_turbo_track: "reload", defer: true
javascript_importmap_tags
end
end
end I tried various other approaches, but since my cosmos project is a static CMS, I preferred it this way. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think this solves the problem you are looking for - https://ruby.social/@joeldrapper/111108744062187487. I recall this conversation about setting a page title without the need for content_for. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want the header title to be dynamic. It is defined/rendered in the ApplicationLayout, but the value needs to be passed from the controller or corresponding view.
In Erb, I would have yield(:title) in the layout and in the view call content_for(:title).
How to do this in Phlex-rails?
Beta Was this translation helpful? Give feedback.
All reactions