I've been working to have a simple php conditional set up in the tpl files for a view. But the automatic loop Drupal does to this file does has been driving me nuts.

My goal is to have a title field become a link only if someone in the CMS says it needs to be linked, say through another field (checkbox).

I'm currently working in the views-view-fields-- filed for my view.

My two fields: my_checkbox (bool) and my_title (string)

$var = $row->field_field_my_checkbox[0]['rendered']['#markup']; 

foreach($fields as $id => $field): 
    if ($var = 0):
        print $fields['field_my_title']->$content; 
    elseif ($var = 1):
        print "<a href>" . $fields['field_my_title']->$content . "</a>"; 

It is good idea to try what I'm doing in this location in the view tpl files? Should I be focusing in the views-view-field-- tpl instead? Which I'm unsure how you could pull another fields output here.

I'd like to stick to coding this and not do this in the CMS for easy re-usability. Thanks in advance.

  • You might check out the Views Conditional module, it works like a charm for this type of thing. – Danny Englander Jul 16 '14 at 22:39
  • I considered it, but I really would like to know if there is any coding method to solving this issue. Especially since I feel I am so close with the method I'm doing it now. – tdm Jul 17 '14 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.