I am exploring a possible feature for an app I am working on. Ideally we would like to be able to symlink templates so we can use them in multiple paths easily, partials are not really a good option for our use case. I have written a custom template resolver built on top of ActionView::PathResolver to accomplish this. I was speaking with eileencodes about this feature and trying to explore the idea of Rails having native support for this, she said I should start a discussion here.
What do people think? I would love to have this natively supported and would be more than happy to work on a PR.
We are using Rails to serve static templates from a Git repo. We have template writers who are writing Ditta style templates that are single sourced. What this means is that they write a template that may be used in various versions of documentation which will live at different urls, ie /v2/template or /v3/template. The source templates live in a /content folder, to simplify their site structuring we are considering having the site live in a separate folder holding its own directory structure with content templates symlinked so they can be in multiple locations inside the site’s structure. I have written a controller and associated prepend view path rule and route to know how to resolve the correct template from that structure.
While partials could work, from a template writing perspective it adds a fair amount of overhead, also symlinks are well understood and a first class citizen of most file systems.
As I understand it, in order to use a partial like being suggested here, the file has to be in the look up path. This would mean that even under this approach templates would resolve in ways that I do not intend, since render uses the view path to find its template candidates.
I have built something similar to this, but I have to handle a lot of what Rails handles out of the box.
Yeah it is rather specific, although it is fairly trivial to implement. There is a file bin read in the template renderer, basically all that needs to happen is that you check if it is a symlink before that and resolve the symlink before reading the file. My reason for bringing it to the core group is that symlinks are a pretty standard feature of the file system so I sort of expected them to just be followed.