0

Is there a way to check if a field with a certain short name exists for a given channel? I'm not checking if a field is left blank, but if it even exists in the field group.

Currently, this only checks for it being blank, but not if it exists. I'm sharing a template for a few channels, but certain fields aren't mirror images of each other per-channel.

{if {segment_1}_code}{{segment_1}_code}{/if}
0

In short, no. The template parser doesn't know whether fields exist or not.

What would you do differently based on a field being empty vs. a field not existing? Don't they end up with the same result (conditional fails)?

2
  • It's not really to do anything differently, but the project strayed in a different direction. Many channels basically have the same layouts and fields, but instead of reworking the fields (since the client already populated a lot of content), I would rather just keep the work minimal on the template side and ignore fields that don't exist, but output their content if they do exist and have content. – jpea Oct 15 '14 at 16:26
  • Right - but I'm wondering how your template code would change in either case? What would you do differently in your syntax if you were checking if exists and not empty vs. simply if not empty? – Derek Hogue Oct 15 '14 at 17:34

Your Answer

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

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