By MacRonin on
I'm working on a template for one of the node types I created that is extended with CCK. I've figured out a lot of what I need (testing for content in a basic field, outputting it if it exists, Outputting my additional CCK fields) but I haven't figured out how(what variable) to test if one of my CCK fields has any content.
If it was a regular field that I wanted to test for content and then print if there was any, I'd just do:
<?php if ($links): ?>
<div class="links">
<?php print $links; ?>
</div>
<?php endif; ?> and this will print my CCK field.
<?php if ($field_budget_ongoing_expenses): ?>
<strong>Ongoing Expenses: </strong><?php print $field_budget_ongoing_expenses[0]['view']; ?> <br />
<?php endif; ?>But how do I test for it being empty? I assume that there is a location in the array that will give me that info, but I am not sure what it is. Any info would be appreciated.
Comments
There's no need for a special spot in the array
Just test on the content you want to output itself!
In fact, that looks like the test is built into your example code.
But in your case,
will test if your CCK field is empty.
There's sort of an example in an old post at our Agaric site.
~ben
People Who Give a Damn :: http://pwgd.org/ :: Building the infrastructure of a network for everyone
Agaric Design Collective :: http://AgaricDesign.com/ :: Open Source Web Development
benjamin, Agaric
One field?
If you don't expect multiple fields, just test for the value of the first field...
Otherwise you need to loop through the array...
That loop should really happen in the template.php file, though, and the output preferably formatted via a theme function and put into a single variable which then gets put into your node template...to keep as much logic out of the node-whatever.tpl.php file as possible.
Hope this makes sense...
Thanks for the info. (both of you)
Thanks for the info. Especially the multi-value one. Most of my fields are single occurrence, but a few will be multiple without a predefined count. That will depend on the user.
-------------------
http://www.PrivacyDigest.com/ News from the Privacy Front
http://www.SunflowerChildren.org/ Helping children around the world