1

My goal is to have a content type that will display an image in a certain panel pane or an embedded video, if the video is present.

I can imagine setting up two fields, one for the image and one for the video embed code. But I'm not sure how to hide the image if the video is present or to make the video field take precedence over the image field in panels.

3 Answers 3

7
+50

It can be done with Views rewriting options.

  1. Add both fields (Image before Video) to Views and exclude Image field from output.
    enter image description here
  2. For Video field set “NO RESULTS BEHAVIOR” to Image field token: enter image description here

It means that if Video field is empty Views will get value from this textarea, which contains special placeholders (in this case [field_image]).

Available tokens for your fields can be found under “REWRITE RESULTS” fieldset: enter image description here

Don't forget to uncheck “Rewrite the output of this field” flag.

1
  • 1
    Ah, that's a clever use of the rewrite field. I should have thought of that. Thanks for the detailed answer. I'll test it out soon.
    – Jay
    Commented Jun 12, 2012 at 12:02
0

Kalabro solution is good if you use a view with fields. If you use a view with "content" you need to go to the content type -> Manage Display and hide image and video field.

Then in the node--YOURCONTENT.tpl.php you can write:

if ($field_image) {
 print $field_image;
}

if ($field_video) {
  print $field_video;
}

Of course you need to change the name of the variables I wrote.

0

It is done with writing the views tpl.By clicking on the theme option of view and you can check the value of your fields in your tpl files like Display Output,Style Output,etc.enter image description here.You can get the code of this tpl file by clicking on the output which you want to check like Display Output,Style Output,etc..Just like I click on the style Output and the code of the style output is displayed as shown in the image enter image description here.Now you can save this file with the name as given in the figure1 in front of the tpl(Display Output,Style Output,etc.).Now you can save this in your enabled theme. for more information of view themeing and views tpl naming please see this. http://drupal.org/node/352970.Now you can check values of fields in this tpl and show as per your requirement. After making the tpl file and placing it in your enabled theme direcory.Now you can click on the rescan template files so that this file will be active and this filename will be shwoing in bold text.

if ($image) {
 print $image;
}
if ($video) {
  print $video;
}

you can change the name of fields($image,$video) above as you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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