Feature #37574
openAllow the use of custom prefix for snippets
Description
We recommend our users to clone default templates that are seeded in DB, instead of unlocking them and modify them directly. The reason is, on every upgrade, the customizations are overridden to the default version. If the user maintains the templates in external git repo and synchronizes all of them in Foreman through foreman_templates, all such templates can be prefixed with something. This is a typical flow, so users end up with templates like
"[acme] Kickstart Default"
Recently, we [[https://projects.theforeman.org/issues/35674|added several]] custom extension points, but they are constructed like this
<%= snippet_if_exists(template_name + " custom pre") -%>
Therefore it tries to load snippets like "[acme] Kickstart Default custom pre". That means also all the snippets need to be cloned and managed separately. This requires a lot of effort.
We should introduce a new Setting under Provisioning to specify a custom prefix, e.g. "[acme] ". If it is specified, both snippet and snippet_if_exists macros should first try to load prefixed snippet and if it does not exist, it should try it without the prefix. That way, the user has always a way to override the default behavior by prefixed version but also an option to continue using the default snippets.
Updated by Alexander Olofsson 5 months ago
Having a parameter on the snippet/snippet_if_exists macros which performs the render without the prefixed lookup would also be useful, for the use-case of being able to soft-fork a snippet - i.e. conditionally choosing to render the original or a replacement.
Updated by Marek Hulán 5 months ago
You mean something like e.g. having a template "[acme] Kickstart" with the following code
snippet 'some', ignore_prefix: true
while the global setting would be set to "[acme] ". That way you may already have the forked snippet but not use it yet, because it may still be debugged? That would likely be an easy addition.