I've created a custom field named $field_get_help. It is an integer Single on/off checkbox with these values:

display|Display Help Box
hide|Hide Help Box

The default "display" should show my HTML listed below, but if "hide" is checked, then DO NOT display the HTML on page.

Can anyone tell me what PHP if statements I'd need in my node template do accomplish this?

HTML to be show by default:

<div class="help_box">
<div class="ghn"><b>Need help?</b><br/>
<a href="/help">Get help now</a>
</div>
</div>

Comments

willvincent’s picture

There should already be some similar examples in the default node template for various things like the links and whatnot..

But, you essentially need an if statement to check the value of your field, and output the appropriate html when necessary.

I'd suggest installing the devel module, and using the dpm() function to inspect the node object in your template to be sure you understand the structure and everything completely.. The code you'll ultimately need should be similar to the following:

EDIT: Looks like you changed your original post, causing my sample code to not make any sense. Removed.

Follow me on twitter.

rewted’s picture

Yes, sorry. I had to clarify my post a little better. The suggestion by Phryk works in preview, but fails to display once the article is saved. Do you know why?

rewted’s picture

Still can't figure out the proper way to do this, looking for more assistance.

rewted’s picture

Any further insight?

phryk’s picture

The field (as least in my experience with D6 + CCK) should be in $node->field_get_help,
this should be an array of arrays, each of the inner array is associative and holding the values associated with a filled field.

Okay that might be a bit confusing (most likely due to my grammar). Here's a notation of what a text-field could look like:

<?php
$node->field_sometext = array(
  0 => array(
    'value' => 'sometext',
    'display' => '<p>sometext</p>',
  ),

  1 => array(
    'value' => 'anothertext',
    'display' => '<p>anothertext</p>',
  ),
);
?>

This is not totally accurate, but should help imagine you how it's built.

Seeing this you can access the value of the first text ('sometext') with $node->field_sometext[0]['value']

So you should be able to do something like this:

  if($node->field_get_help[0]['value'] == 'display'){
    print 'this be help.';
  }
rewted’s picture

The print displays during preview, but once saved, doesn't show up in the article. Any idea why?

rewted’s picture

Found the issue. It was because I initially set the checkbox as an integer, so using "display" will not work. Deleting, re-creating as text, display now works. Another solution would be changing the checkbox to a number.

WorldFallz’s picture

Please don't post duplicate threads, I've deleted the dupe(s). Thanks.

rewted’s picture

I'm not. The other post is related to display issues in preview vs saving.