0

I'm using some custom node.tpl.php files with lots of custom fields. For each field I have to write down <?php if (isset($content['field_myfield'])):?> SOMETHING <?php endif; ?>

(It gives error if that field is not set without using if isset condition.)

Is there anyway to define a 'global' if (isset...): instead of adding if condition to each field separately?

2
  • 1
    isset() can take multiple arguments, if that helps.
    – mona lisa
    Commented Jun 22, 2016 at 15:04
  • 1
    Make an array of your fields and pass it to a custom function, I guess...
    – No Sssweat
    Commented Jun 23, 2016 at 8:16

1 Answer 1

1

No. Consider the case where one field is not set. Either the global if fails and nothing is printed or you are right back to those errors. This is one of the shortcomings of coding in the theme layer.

1
  • Thanks for your answer, I will still try to find a better solution to this.
    – herci
    Commented Jun 22, 2016 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.