amariotti.com

  • about
  • blog
  • portfolio
  • resumé
  • modules
  • contact
Home › Blogs › amariotti's blog

Recent blog posts

  • Text Formatter Module
  • Cool Apache ReWrite Trick
  • New RSS Feed
  • Find My iPhone
  • Congratulations, Drupal!
  • Re-Launched on Drupal 6
  • Copying + Pasting from Word into Drupal
  • Page Not Found on Node Creation
  • 1 Year
  • Happy Birthday WWW!
more

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

Blog tags

drupal drupal 6 drupal issue liquidweb module modules that I love os x random rss Salesforce.com software theming
more tags

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!

  • cck
  • contemplate
  • tricks
  • amariotti's blog
  • 4048 reads

Awesome bit of code, thanks

Zoran (not verified) — Mon, 03/30/2009 - 20:00

Awesome bit of code, thanks for sharing this!play roulettepoker reviewsplay blackjackonline video pokerdownload divx movie

  • reply

thanks for the intro, i have

Kevin (not verified) — Tue, 05/19/2009 - 00:09

thanks 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?

  • reply

Yes, that's where you would

amariotti — Tue, 05/19/2009 - 09:19

Yes, 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. :)

  • reply

Cool! It works perfectly..

Pipicom (not verified) — Wed, 06/03/2009 - 14:54

Cool! It works perfectly..

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <b> <p> <br>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You may use <swf file="song.mp3"> to display Flash files inline

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
18 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
  • about
  • blog
  • portfolio
  • resumé
  • modules
  • contact