Snippets are small templates that are called from larger main templates. When both are rendered together, the snippet's content appears inline. However, even though both the main template and the snippet are rendered together, due to variable scoping, a snippet is unable to reference a normal variable set in the calling template.
The following example is generating scoping errors or SafeMode Rendering errors when attempted.
<% myvariable = 'This is my value' -%> <%= snippet 'mysnippet'%>
# Oversimplified Snippet Example named: 'mysnippet' Inside the snippet, the value set in my calling template is: <%=myvariable> %>
SafeMode Rendering turned on, rendering the above will yield an error that SafeMode has prevented access to the variable:
There was an error rendering the oversimplified_provisioning template: ERF42-7327 [Foreman::Exception]: The snippet 'mysnippet' threw an error: Safemode doesn't allow to access 'myvariable' on #<Safemode::ScopeObject>
SafeMode Rendering turned off, rendering the above will yield an error about an undefined variable in the snippet:
There was an error rendering the oversimplified_provisioning template: ERF42-7327 [Foreman::Exception]: The snippet 'mysnippet' threw an error: undefined local variable or method 'myvariable'
Red Hat Satellite 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.