-
I am making a filter component so I have one parent that has a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Hi again @coder2000! You might be interested in using template variants for this purpose. Those docs link to this part of the Rails docs. If you don't prefer this pattern and would rather specify within your component which component you'd like to render for your slot, a couple of methods come to mind:
class OptionsComponent > ViewComponent::Base
attr_reader :mobile
def initialise(mobile: false)
@mobile = mobile
end
renders_many :options, -> { mobile ? ExampleComponent.new : OtherComponent.new }
end
<% unless mobile %>
<% options.each do |option| %><%= option %><% end%>
<% end %> I hope that answers your question! |
Beta Was this translation helpful? Give feedback.
Hi again @coder2000! You might be interested in using template variants for this purpose. Those docs link to this part of the Rails docs.
If you don't prefer this pattern and would rather specify within your component which component you'd like to render for your slot, a couple of methods come to mind:
<% unle…