Recent blog posts
Recent comments
- Turning off PHP suhosin
36 weeks 2 days ago - The code for D5 is posted
36 weeks 3 days ago - Repost the code please :)
37 weeks 1 day ago - Hi, very nice post. I have
38 weeks 3 days ago - Great post! I'll subscribe
38 weeks 6 days ago - Cool! It works perfectly..
40 weeks 1 day ago - I'm having the same problem.
40 weeks 6 days ago - Hello again. It's working but
40 weeks 6 days ago - I'm having the same issue, it
41 weeks 8 hours ago - Yes, when I open the page I
41 weeks 8 hours ago
Hiding CCK Fields when using Contemplate Module
amariotti — Mon, 08/11/2008 - 15:22
At work I am building some pretty complex content driven pages with Contemplate. I have some node data being displayed in the main content area and the rest in a dynamic block using Views Arguments. To keep a better handle on the data being displayed I am the Contemplate module, which I have found to be an extraordinary module for what it can do.
I ran into an issue today where I wanted to hide the label to the field if the field was empty. After some searching online and digging I couldn't really find anything, so I did a little research on my own and was able to come up with the solution. Here it is:
<?php if ($node->your_field_name[0]['view'] != ""): ?>
<div class="field-item"><div class="your_label_class">Your label: </div><?php print $node->your_field_name[0]['view'] ?></div>
<?php endif; ?>Be sure and replace <code>field_your_field_name</code> with your field name. Also be sure and put in your own custom css class for the label to make it your own!
So there it is!
- amariotti's blog
- 4048 reads

Awesome bit of code, thanks
Zoran (not verified) — Mon, 03/30/2009 - 20:00Awesome bit of code, thanks for sharing this!




thanks for the intro, i have
Kevin (not verified) — Tue, 05/19/2009 - 00:09thanks for the intro, i have one question,
your_class_here">your_label_class">
Is that you means we can define any name of the div class here?
Yes, that's where you would
amariotti — Tue, 05/19/2009 - 09:19Yes, that's where you would put your class for your label. I wanted to emphasize that so that everyone knows that that can be whatever they need it to be. Guess I should've specified that in the post. :)
Cool! It works perfectly..
Pipicom (not verified) — Wed, 06/03/2009 - 14:54Cool! It works perfectly..
Post new comment