Hey, I have created a yes/no checkbox for my nodes, this is just a thing saying display link to "blah blah" so if they check it, then the link will be on the node. I have yet to figure how to do this. I have created the check box like this

0|dont display
1|Display link on node

but I have yet to see anything in the variables list after checking and unchecking it.

Comments

jrglasgow’s picture

I created a content type I called 'checkbox', this content type included a 'Single on/off checkbox' with the 'Allowed values':

No
Yes

So 'No' is the unchecked value and 'Yes' is the checked value.

The following is in my variables for teaser, body, etc...

$node->field_show_link (array)

    $node->field_show_link[0] (array)

        $node->field_show_link[0]['value'] **
            No 
        $node->field_show_link[0]['view']
            No 


When the checkbox is checked this is what I get:

$node->field_show_link (array)

    $node->field_show_link[0] (array)

        $node->field_show_link[0]['value'] **
            Yes 
        $node->field_show_link[0]['view']
            Yes 

To help you any more I would need to see a list of your available variables.

mike.hobo’s picture

Is this the Interger checkbox or the Text checkbox?

jrglasgow’s picture

the above example uses a Text: Single on/off checkbox, I tries it with an Integer checkbo and this is what I get with the checkbox checked:

$node->field_checkbox2 (array)

    $node->field_checkbox2[0] (array)

        $node->field_checkbox2[0]['value'] **
            1 
        $node->field_checkbox2[0]['view']
            Display link on node 


and this is what I get with the checkbox unchecked:

$node->field_checkbox2 (array)

    $node->field_checkbox2[0] (array)

        $node->field_checkbox2[0]['value'] ** (NULL)
        $node->field_checkbox2[0]['view']

so you should be able to do it this way:

  <?php
    //some pseudo code
    if($node->field_checkbox2[0]['value']){
      /**
       * since NULL == false and 0 == false 
       * and anything <> 0 is true by default 
       * you don't have to use any logical operators
       */
      print $link;
    }
  ?>
mike.hobo’s picture

Wow sweet! very helpful!

mike.hobo’s picture

Hmm, I see to be having a problem, whenever it is checked, and then edited and unchecked it says

warning: Cannot use a scalar value as an array in /home/byc/public_html/pdxfm/modules/cck/content.module on line 587.

jrglasgow’s picture

are you using the latest version of contemplate 5.x-1.9, if not please upgrade to this then give me any errors you get

mike.hobo’s picture

Version: 5.x-1.8 » 5.x-1.9

I have 5.x-1.9 now, but I am thinking that this is a CCK problem.

jrglasgow’s picture

I did not have this problem when I tested this solution. It could also be your version of PHP.