title: How do I pass variables to theme template via custom controller drupal 8
body: <p>I currently have a theme I purchased installed on my Drupal website.</p>
  
  <p>Inside the theme folder there is a templates folder that contains:</p>
  
  <ul>
  <li>page.html.twig</li>
  <li>page--front.html.twig</li>
  </ul>
  
  <p>a snippet from <strong>page.html.twig</strong> looks as follows:</p>
  
  <pre><code>    &lt;footer class="site-footer"&gt;
    &lt;div class="layout-container"&gt;
      {% if page.footer_first or page.footer_second or page.footer_third %}
        &lt;div class="footer-top"&gt;
          &lt;div class="footer-top-inner"&gt;
            {{ page.footer_first }}
            {{ page.footer_second }}
            {{ page.footer_third }}
          &lt;/div&gt;
        &lt;/div&gt;
      {% endif %}
  
      {% if page.footer_left or page.footer_right %}
        &lt;div class="footer-bottom"&gt;
          &lt;div class="footer-bottom-inner"&gt;
            {{ page.footer_left }}
            {{ page.footer_right }}
          &lt;/div&gt;&lt;!-- /.footer-bottom-inner --&gt;
        &lt;/div&gt;
      {% endif %}
    &lt;/div&gt;
  &lt;/footer&gt;
  </code></pre>
  
  <p>I have a custom module I created (business_listing) that loads different .html.twig templates I add these templates in <strong>business_listing.module</strong>:</p>
  
  <pre><code>        function business_listing_theme($existing, $type, $theme, $path) {
  
        return [
          // business-listing-detail.html.twig
          'business_listing_detail' =&gt; [
              'variables' =&gt; ['data' =&gt; [], 'slides' =&gt; [], 'paths' =&gt; [], 'page' =&gt; []],
          ],
       ]
     }
  </code></pre>
  
  <p>Basically I would like to know how I can add the markup for the footer dynamically from my custom modules controller. </p>
  
  <p>I have a page called  <strong>business-listing-detail.html.twig</strong> inside my custom modules templates folder. From what I understand <strong>business-listing-detail.html.twig</strong> uses/somehow extends <strong><em>page.html.twig</em></strong> in my theme/templates. What I would now like to know is how I can add the sections like <code>{{page.footer_left}}</code> to my business-listing-detail.html.twig or to page.html.twig using my controller? I have tried adding the footer using the following: `       </p>
  
  <p>$page['footer_left'] = "This should appear in the .footer-bottom div?";</p>
  
  <pre><code>    $build = [];
      $build['business_listing_detail'] = [
        '#theme' =&gt; 'business_listing_detail',
        '#data' =&gt; $record,
        '#slides' =&gt; $slides,
        '#paths' =&gt; $this-&gt;paths,
        '#page' =&gt; $page
      ];`
  </code></pre>
  
  <p>in the controller function associated to my business-listing-detail page the hopes that <strong>page.html.twig</strong> will detect this page.footer_left and render display the footer, however this did not work. The variable exists in business-listing-detail.html.twig but the <code>{% if page.footer_left %}</code> in my themes page.html.twig is not fired. Please please please, any help or advice would be greatly appreciated &lt;3 </p>
  
  <p>Basically all I am trying to do, is dynamically render a template for a specific page in my custom module, that allows me to implement/send markup to the sections/regions defined in my theme eg. featured_top, content_top &amp; page.content</p>
  
  <p>Kind regards,
  Matt</p>