title: How to read custom data variable sent in all twig files in opencart?
body: <p>i am trying developing an extension for opencart.
  I'm using trying to read the custom flag variable &quot;dataopen_location&quot; in all the twig files . This variable(dataopen_location) is used in twig files to decide if to open all links in new tab or not. This variable is set in the admin panel(homepage) of the extension by the user. I am trying to add the variable in <code>$data</code> array in all controller files .The code used to send data in the controller file:</p>
  <pre><code>&lt;file path=&quot;catalog/controller/*/*.php&quot;&gt;
      &lt;operation&gt;
        &lt;search&gt;&lt;![CDATA[$this-&gt;response-&gt;setOutput($this-&gt;load-&gt;view('error/not_found', $data));]]&gt;&lt;/search&gt;
        &lt;add position=&quot;before&quot;&gt;&lt;![CDATA[ 
          if ($this-&gt;config-&gt;get('module_dataopen_location') == 1){
            $data['dataopen_location'] = &quot;1&quot;;
   }
           ]]&gt;&lt;/add&gt;
      &lt;/operation&gt;
    &lt;/file&gt;
  </code></pre>
  <p>Then in the twig files I have a 'if' condition that checks if &quot;dataopen_location&quot; is set or not.The code used for updating the .twig files in install.xml</p>
  <pre><code>    &lt;file path=&quot;catalog/view/theme/*/template/*/*.twig&quot;&gt;
      &lt;operation&gt;
        &lt;search&gt;&lt;![CDATA[&lt;a href]]&gt;&lt;/search&gt;
        &lt;add position=&quot;after&quot;&gt;&lt;![CDATA[{% if dataopen_location==1 or dataopen_location=='1' %}target=&quot;_blank&quot;{% else %}target=&quot;_parent&quot;{% endif %} ]]&gt;&lt;/add&gt;
      &lt;/operation&gt;
    &lt;/file&gt;
    &lt;file path=&quot;catalog/view/theme/*/template/*/*/*.twig&quot;&gt;
      &lt;operation&gt;
        &lt;search&gt;&lt;![CDATA[&lt;a href]]&gt;&lt;/search&gt;
        &lt;add position=&quot;after&quot;&gt;&lt;![CDATA[{% if dataopen_location==1 or dataopen_location=='1'   %}target=&quot;_blank&quot;{% else %}target=&quot;_parent&quot;{% endif %}]]&gt;&lt;/add&gt;
      &lt;/operation&gt;
    &lt;/file&gt;
    &lt;file path=&quot;catalog/view/theme/*/template/*/*/*/*.twig&quot;&gt;
      &lt;operation&gt;
        &lt;search&gt;&lt;![CDATA[&lt;a href]]&gt;&lt;/search&gt;
        &lt;add position=&quot;after&quot;&gt;&lt;![CDATA[ {% if dataopen_location==1 or dataopen_location=='1' %}target=&quot;_blank&quot;{% else %}target=&quot;_parent&quot;{% endif %} ]]&gt;&lt;/add&gt;
      &lt;/operation&gt;
    &lt;/file&gt;
  </code></pre>
  <p>But every time the 'else' condition gets displayed ie. target=&quot;<em>parent&quot; even if the variable &quot;module</em> dataopen_location&quot; is set to 1.Can some one point out what i am doing wrong?am using the correct variable($data) to send (append 'dataopen_location') the flag? if not, where should i add the controller code?
  I am using opencart version <strong>3.0.3.8</strong>
  I am very new to ocmod and stackoverflow so i am sorry if i missed some of the best practices, please help me.</p>
  <p>note: i know opening all links in a new tab will break the website,but that is not the issue.</p>