-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phoenix.Template only compiles templates in the immediate directory #1228
Comments
This is by design because it's much simpler. Would it be feasible to use another view per institution and render templates that way? |
It would be possible but not ideal because:
|
How man institutions are we talking? Can you forgo nesting and use a prefix instead? render(conn, "#{enrollment.institution}-#{enrollment.state}.html", enrollment: enrollment) |
I think that's what I'm going to do for the moment until either this is implemented in Phoenix or I dream up a different abstraction 😊. I have ~15 institutions in one territory (the UK), each one has 3-5 states. Ultimately there will be a large number of institutions, i.e. the amount of banks in the world, institution == bank for all intents and purposes. Sorry to bother you with what might seem like a niche requirement, times like these I really miss Ruby's open modules! |
Yeah, a large directory will be the way to go. We will keep an eye open. If a lot of folks need this, we may make it configurable. Also, let's not forget to move those discussions to the core mailing list folks. :) |
FWIW, my team recently ran into this same issue. The use case is similar to the OP's: we are building an application which needs a way to hygienically offer multiple sets of templates for the same core functionality. We need this for whitelabeling support, which is often combined with a multi-tenant environment in which there is one deployed instance of the application (perhaps spread over several VMs / physical machines, but operating as a single instance) that needs to reflect both the primary brand as well as, depending on access details (e.g. domain name, path, headers, ..), customer brands. This is a bit more than simple skinning ("change the colours, move things around the page") and many times requires material adjustment to forms and other elements. Installing and updating the whitelabel components for a customer (or "tenant") needs to be easy and provide some level of "won't conflict with other installed things" safety. Living in the same tree in a deployment is fine, but they do need to added (or removed) post-installation and not be contained in the main product directly. The "easy" approach, and one the developers are familiar with from elsewhere, is to put each of these whitelabel bundles in their own package and install them in a subdirectory associated with the installed instance. We're looking at other possible approaches (after all: "what you know is not always the only, let alone best, way"), but having all the templates necessarily co-mingling in one directory is a bit unfortunate. tl;dr -> we've hit the same "gotcha", though we are not sure it is a blocker .. certainly a bit of a thinker, though. |
This has been added to Phoenix though in a later pull request. Please check On Wednesday, August 31, 2016, aseigo [email protected] wrote:
José Valimwww.plataformatec.com.br |
❤️ ❤️ ❤️ ❤️ |
For others who stumble here, the key is the setup of Phoenix.View in e.g. web/web.ex def view do note the use of "pattern" there, which is the new thing José is referring to above. This was added in 1.2.0. Thank-you for the responses and for those who made this improvement a reality :) |
After making the change, I get |
@pauloancheta Try |
@viniciussbs did that work in compiled application as well? In my case adding |
@lessless I don't know. The app that uses this pattern is not compiled. :-| |
Hi all,
I found that that
Phoenix.Template.__before_compile__/1
does not recurse through subdirectories when compiling templates and only compiles the templates in the immediate directory. I think I've tracked this down toPhoenix.Template.find_all/1
, i.e. the path search does not include a glob parameter. The docs forPath.wildcard/1
indicate**
will match 0 or more subdirectories. Perhaps this can be fixed by changing the pattern toPath.wildcard("#{root}/**/*.{#{extensions}}")
?My use case is conditionally rendering a template depending on the state of the resource, e.g. Enrolling a bank account in http://teller.io. There are many supported banks and enrollment is a multistep process so I want to do something like.
This currently raises a `Phoenix.Template.UndefinedError
The text was updated successfully, but these errors were encountered: