5

I am creating a website in which, there is a view that displays content, and then several icons. theses icons tell the user weather something is available, for example, the icons on this site show you that there is no sound available to listen to, but there is a video to watch. the icons are as follows:

screenshot

The "find it" and the video buttons are black, but the rest of the buttons are grayed out. (They are actually displaying two different images depending on weather or not there is something to link to.) The reason that they are grayed out is that there is nothing available for them to link to.

What I want is something very similar; I want several icons that will be either grayed out or black, depending on weather or not a checkbox in one of my CCK fields is checked.

How would I go about doing this? Can I do it with a view? Is there a script that I can use?

3

If you want to do it inside of your content, while not using a view, you can add some conditional php to a custom node template file...so if your content type is named "train", you can create a file named "node-train.tpl.php" and put it within your theme's folder.

In your node-train.tpl.php file, you can display the content of that node based on some cck value that is selected when you create a train node. Here's an example of the code:

<?php if($node->field_image_select[0]['value'] =='Image 1'):?>
//If the author selects the cck checkbox value of "Image1" display this.
<img src ="../path/to/image/image1.jpg />
<?php endif;?>

<?php if($node->field_image_select[0]['value'] =='Image 2'):?>
 //If the author selects the cck checkbox value of "Image1" display this.
<img src ="../path/to/image/image2.jpg />
<?php endif;?>

If you want to do this within a views display, you'll need to create a view that displays your train node only and set the display type to "node" (it defaults to display type "fields")...let's say you named the view "train_summary", then within your theme's folder you would create a new file named "node-view-train_summary.tpl.php" - You can use the code example from above in the file you just created and every time that type of view is displayed on your site, you'll see the output from that code.

| improve this answer | |
3

You will have to rewrite the results of your fields. NodeOne has some videos that describes what to do and I think this one http://nodeone.se/blogg/learn-views-with-nodeone-part-17-rewriting-fields will have the info you need.

Short answer is that you will configure field > Rewrite Results > Rewrite the output of this field and then use the "REPLACEMENT PATTERNS" that will show only the fields that are available (can't use fields that come after in the list).

You can use [field_NAME]_icon.png where the [field_NAME] will either be black or grey to load the correct icon. This would work if Black and Grey were the allowed values of a radio button for each field. Checkboxes should be similar, but I didn't need to use them for my issue.

| improve this answer | |
  • what if I wanted to do this inside of the content, instead of a view? if I need to do with a view, is there a wa to make a view that has each content individually basically copying exactly what the content page is? – Ephraim Aug 17 '11 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.