title: Inheritance with Twig in Grav
body: <p>I’m new to Twig, having just recently built a blog using Grav CMS, which I’m also new to.</p>
  
  <p>I added the following to one of my partials:</p>
  
  <pre><code>{% set csp_nonce = 'nonce-' ~ random_string(20)|base64_encode %}
  </code></pre>
  
  <p>I could then access it later in the same template as follows:</p>
  
  <pre><code>    &lt;meta http-equiv="X-My-Nonce" content="{{ csp_nonce }}"&gt;
  </code></pre>
  
  <p>This was a quick way to see if I had been successful by viewing the generated source code.</p>
  
  <p>However as I want to use that <code>csp_nonce</code> value multiple times in one page, so I can allow inline styles and scripts with a content security policy, without resorting to using <code>'unsafe-inline'</code>, I thought I’d pop that code in a template of its own and call that when needed. I’ve tried <code>include</code>, <code>embed/endembed</code>, <code>use</code> and <code>extends</code> but all I seem to achieve is either a twig error about having content outside a block or no error but anywhere I’ve included the child template and then try to access the <code>csp_nonce</code> value it’s empty (so I’m guessing I’m falling foul of a scoping issue but struggling to get my head around it.</p>
  
  <p>Any help greatly appreciated!</p>
  
  <p><strong>EDIT:</strong>
  I managed to get it to work by just putting the <code>{% set csp_nonce...</code> into each parent twig. Which for now will do as now the value is available to use everywhere I need it. But I know there’s a better way I’m just not seeing.</p>