Skip to content

How to call a named template #2068

Answered by boardfish
bufordtaylor asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @bufordtaylor, thanks for opening this! I think what this code is pointing towards is that this markup is different enough to warrant new components for each case. Rather than having the template or component class contain lots of conditionals to switch behaviour, you'll most likely want to break these out into separate components.

If you wanted ListComponent to be the interface folks use to render this component, though, you could make that a factory class:

# Intentionally doesn't inherit from ViewComponent::Base: this is a plain old Ruby factory class.
class ListComponent
  def self.new(preference)
    case preference
    in :compact_row
      CompactRowComponent.new
    in :standar…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bufordtaylor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants