Hi, I'm looking for a quick fix to some code...

I need the code to be reformatted so that it successfully prints the same results but in a views-view-field--field-video-fid.tpl.php

    // Displays the media player with an Imagefield preview and the Play icon turned off
      print swf($node-> field_video_advert [0]['filepath'],
        array(
        'params' => array('width' => '300', 'height' =>'300'),
        'flashvars' => array(
          'image' => 'activity_event_images/' . ($node-> field_image_product [0]['filename']),
          'icons' => 'false')
       ));
  

Any help is greatly appreciated. Thanks

Evelyn

Comments

Stuff’s picture

You have one to many arrays in between the params and flashvars.

try this

<?php
    // Displays the media player with an Imagefield preview and the Play icon turned off
      print swf($node-> field_video_advert [0]['filepath'], 
        array(
        'params' => array('width' => '300', 'height' =>'300'),
        'flashvars' => array(
          'image' => 'activity_event_images/' . ($node-> field_image_product [0]['filename']),
          'icons' => 'false')
       ));
   
?>

http://drupal.org/node/305225

nyleve101’s picture

Thank you sooo much! I have no idea how i missed that page. You don't by any chance happen to know where i can find info on how to print that in a views field template like views-view-field--field-video.tpl.php do you?

Again, thank you so much!

I hope you're well and taking care of yourself.

Evelyn

Stuff’s picture

Not 100% sure but you should probably use the row output instead, use the "themeing information" link within views to retrieve the base code then overwrite the file so its the lowest one relevant to your view,

<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>
//Generate your video output here.
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      // $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      ?>
      //create an if statement to check the $field->handler here and output the video if true or else default. 
      <<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
<?php endforeach; ?>

From here I would probably create the video output prior to the foreach and then create an if statement on the content output to check the field-handler to determine if its the field your after and replace accordingly..

step 1 create the content

you can use $fields['field_name']->content to retrieve the content of the field, so in the view set the output type of your image and file in the view to filepath and you will have all the details you need to produce the swf output.

I always remind myself that all the view is doing is creating a long print output so you can replace the filepath field with your desired output later without to much trouble its your view after all and thats what the templates are there for.

step 2 the if

then using the field handler check which content field is being created and output the video if its the filefield your after.

will take a fair bit of fiddling around and probably a few print_r();
but that should get you there.

Also if its just one result you can always remove the foreach and just do a print of what you need just make sure you are only effecting the relevant view!!

nyleve101’s picture

Thanks for all your help it's been much appreciated! I decided to put my headache to rest and use the simpler option of plain images for my views.

Take care of yourself and thanks again!

nyleve101’s picture

Bounty closed! The Views issue has been successfully and might i add speedily solved by Fabianx

Fabianx and Stuff thank you both so much for your help!

Evelyn

nyleve101’s picture

Hi,

this is the views template code in case anyone else needs it. You'll need to change the fields and of course change the image cache preset so that it matches your own.

views-view-field--field-video-advert-fid.tpl.php

// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
 /**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  *
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  *
  * The above will guarantee that you'll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  */

// Get file ids

$fid_video = $row->{$field->field_alias};

// Find real field alias for image field

$fid_image = false;

$suffix = "field_image_product_fid";
 
foreach($row as $key => $val)
	if (substr($key, -1*strlen($suffix)) == $suffix)
		$fid_image = $val;

// If we got some data, display it.

if (!empty($fid_video) || !empty($fid_image))
{
    $node = (object)array();

    $node->field_video_advert[0] = field_file_load($fid_video);
    $node->field_image_product[0] = field_file_load($fid_image);

    // Check if we got an image

    if ($node-> field_video_advert[0]['filepath']!='')
    {
     
     // Displays the media player with an Imagefield preview and the Play icon turned off
     print swf($node-> field_video_advert [0]['filepath'],
        array(
        'params' => array('width' => '210', 'height' =>'180'),
        'flashvars' => array(
          'image' => 'activity_event_images/' . ($node-> field_image_product [0]['filename']),
          'icons' => 'false')
       ));
    }
    else
      print theme('imagecache', 'product_image', $node->field_image_product[0]['filepath']);
}	

Hope all is well!

Evelyn