Sharing partials (templates) between slices

Hello, how can I have a partial that can be rendered in both app and across the slices? The actual use-case is related to the flash messages.

I tried just rendering, but slices search in their own templates directory, any way to customize it?
Also, with some chat hints and by reading docs I tried to achieve it with scope, but even scope defined in app when used in slice was searching in slice’s templates when rendering.

I came up with this solution:

# auto_register: false
# frozen_string_literal: true

module Accounts
  class View < MyProject::View
    config.paths = %w[
      slices/accounts/templates
      app/templates
    ]
  end
end
2 Likes

Thanks for sharing, I think I will have this use case one day :hugs:

1 Like

Nice solve, @buszu! This is what I would have done too. :slight_smile:

You can make it a touch nicer by appending to paths rather than overwriting it:

config.paths += ["app/templates"]

This means that you don’t need to worry about replicating the default path Hanami provides for the slice, and just add the special one.

1 Like