Answers.Body: <p>OK. I figured it out eventually. This is how I got it to work. It seems a little wonky but it functions</p>
  
  <ol>
  <li>Add the column to the list of columns </li>
  <li>Override the template</li>
  <li>Alter the rows to add the link</li>
  <li>AND unset the column in Alter rows</li>
  </ol>
  
  <p><strong>The constructor columns must contain</strong></p>
  
  <pre><code>  ts('Org id') =&gt; 'org_id',
  </code></pre>
  
  <p><strong>The override</strong></p>
  
  <pre><code>  public function templateFile() {
      return "CRM/Contact/Form/Search/Custom/mySearch.tpl";
    }
  </code></pre>
  
  <p><strong>The template</strong></p>
  
  <p>Add snippets in each of the column headers section and the rows section skipping an item in the loop. Eg. <code>{if $header.sort neq 'org_id'}</code></p>
  
  <p>For the headers:</p>
  
  <pre><code> {foreach from=$columnHeaders item=header}
      {if $header.sort neq 'org_id'}
        &lt;th scope="col"&gt;
        {if $header.sort}
          {assign var='key' value=$header.sort}
          {$sort-&gt;_response.$key.link}
        {else}
            {$header.name}
        {/if}
       &lt;/th&gt;
     {/if}
  {/foreach}
  </code></pre>
  
  <p>For the rows:</p>
  
  <pre><code>{foreach from=$columnHeaders item=header}
     {assign var=fName value=$header.sort}
     {if $header.sort neq 'org_id'}
       {if $fName eq 'sort_name'}
         &lt;td&gt;&lt;a href="{crmURL p='civicrm/contact/view' q="reset=1&amp;cid=`$row.contact_id`&amp;key=`$qfKey`&amp;context=custom"}"&gt;{$row.sort_name}&lt;/a&gt;&lt;/td&gt;
        {else}
          &lt;td&gt;{$row.$fName}&lt;/td&gt;
        {/if}
     {/if}
  {/foreach}
  </code></pre>
  
  <p><strong>The alter rows</strong></p>
  
  <p>Note the added unset line.</p>
  
  <pre><code>function alterRow( &amp;$row ) {
    $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&amp;cid={$row['org_id']}");
    $row['organization_name'] = "&lt;a href=\"{$url}\"&gt;{$row['organization_name']}&lt;/a&gt;";
    unset($row['org_id']);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-22T18:50:35.880Z
Answers.LastActivityDate: 2020-04-22T18:58:14.960Z
Answers.LastEditDate: 2020-04-22T18:58:14.960Z
Answers.UserDisplayName: lolcode
Body: <p>I have created a custom search based on relationships.
  Each row shows a contact and a related organisation in separate columns as well as other info.
  Each contact is automatically linked to the view page in the search results but I would like the organisation to also be linked. I return a column aliased to "org_id"  in the <code>all</code> function select piece.</p>
  
  <pre><code>, tempTable.org_id
  , tempTable.organization_name
  </code></pre>
  
  <p>I have not added <code>org_id</code> to my columns array in the constructor because I do not want it to display. If I do then the template file works but I have an extra column.</p>
  
  <p>I have sucessfully overridden the template file as follows:</p>
  
  <pre><code>{if $fName eq 'sort_name'}
     &lt;td&gt;&lt;a href="{crmURL p='civicrm/contact/view' q="reset=1&amp;cid=`$row.contact_id`&amp;key=`$qfKey`&amp;context=custom"}"&gt;{$row.sort_name}&lt;/a&gt;&lt;/td&gt;
  {elseif $fName eq 'organization_name'}
     &lt;td&gt;&lt;a href="{crmURL p='civicrm/contact/view' q="reset=1&amp;cid=`$row.org_id`&amp;key=`$qfKey`&amp;context=custom"}"&gt;{$row.organization_name}&lt;/a&gt;&lt;/td&gt;
  {else}
     &lt;td&gt;{$row.$fName}&lt;/td&gt;
  {/if}
  </code></pre>
  
  <p>It does display a link on the organisation name cell. However the template is not seeing the <code>org_id</code> value and the link stops at <code>cid=</code> EG. <code>civicrm/contact/view?reset=1&amp;cid=&amp;key=fb7ffdb351588d7d7d9df84f3b3e03f5_1119&amp;context=custom</code></p>
  
  <p>Edit: I have also tried this without the template override and used alterRow. This also only works if the <code>org_id</code> result column is added to the columns list of the custom search.</p>
  
  <pre><code>  function alterRow( &amp;$row ) {
      $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&amp;cid={$row['org_id']}");
      $row['organization_name'] = "&lt;a href=\"{$url}\"&gt;{$row['organization_name']}&lt;/a&gt;";
    }
  </code></pre>
  
Tags: <templates><custom-search>
Title: How do I use a hidden column in a custom search template?
ThreadText: # How do I use a hidden column in a custom search template?
  
  (Asked by: username_0 on 2020-04-22)
  
  I have created a custom search based on relationships.
  Each row shows a contact and a related organisation in separate columns as well as other info.
  Each contact is automatically linked to the view page in the search results but I would like the organisation to also be linked. I return a column aliased to "org_id"  in the all function select piece.
  , tempTable.org_id
  , tempTable.organization_name
  
  I have not added org_id to my columns array in the constructor because I do not want it to display. If I do then the template file works but I have an extra column.
  I have sucessfully overridden the template file as follows:
  {if $fName eq 'sort_name'}
     {$row.sort_name}
  {elseif $fName eq 'organization_name'}
     {$row.organization_name}
  {else}
     {$row.$fName}
  {/if}
  
  It does display a link on the organisation name cell. However the template is not seeing the org_id value and the link stops at cid= EG. civicrm/contact/view?reset=1&cid=&key=fb7ffdb351588d7d7d9df84f3b3e03f5_1119&context=custom
  Edit: I have also tried this without the template override and used alterRow. This also only works if the org_id result column is added to the columns list of the custom search.
    function alterRow( &$row ) {
      $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$row['org_id']}");
      $row['organization_name'] = "{$row['organization_name']}";
    }
  
  **Tags:** templates, custom-search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-22. Score: 2
  
  OK. I figured it out eventually. This is how I got it to work. It seems a little wonky but it functions
  
  Add the column to the list of columns 
  Override the template
  Alter the rows to add the link
  AND unset the column in Alter rows
  
  The constructor columns must contain
    ts('Org id') => 'org_id',
  
  The override
    public function templateFile() {
      return "CRM/Contact/Form/Search/Custom/mySearch.tpl";
    }
  
  The template
  Add snippets in each of the column headers section and the rows section skipping an item in the loop. Eg. {if $header.sort neq 'org_id'}
  For the headers:
   {foreach from=$columnHeaders item=header}
      {if $header.sort neq 'org_id'}
        
        {if $header.sort}
          {assign var='key' value=$header.sort}
          {$sort->_response.$key.link}
        {else}
            {$header.name}
        {/if}
       
     {/if}
  {/foreach}
  
  For the rows:
  {foreach from=$columnHeaders item=header}
     {assign var=fName value=$header.sort}
     {if $header.sort neq 'org_id'}
       {if $fName eq 'sort_name'}
         {$row.sort_name}
        {else}
          {$row.$fName}
        {/if}
     {/if}
  {/foreach}
  
  The alter rows
  Note the added unset line.
  function alterRow( &$row ) {
    $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$row['org_id']}");
    $row['organization_name'] = "{$row['organization_name']}";
    unset($row['org_id']);
  }
  
  
  ---
  
  