Make a swf file available in your template.

Last modified: December 5, 2008 - 20:40

So there is a flash file used in the sites template, ie. on every page. This is a very simple example to illustrate method. You can see that width, height are based on the flash file, usually we force this to be exact for a template since it will often line up with non-flash elements. Also, a background color is set.

In your _phptemplate_variables section of your template.php, add this in side the case 'page': switch.

<?php
function  _phptemplate_variables($hook, $vars) {
   switch(
$hook) {
     case
'page' :
        
$vars['swf_logo'] = swf(
   
"http://example.com/files/banner.swf",
    array(
'width' => '420', 'height' => '140', 'bgcolor' => '#336699'), FALSE,
    array(
'html_alt' => '<h1>Name of site if flash is disabled.</h1>')
  );
        break;
   }
   return
$vars;
}
?>

Then in the page.tpl.php:

<?php
print $swf_logo
?>

at the appropriate spot.

template for D6

jokerejoker - December 17, 2008 - 12:16

The correct code is

<?php
function  themeName_preprocess(&$vars, $hook) {
  switch(
$hook) {
    case
'page' :
     
$vars['swf_logo'] = "http://example.com/files/banner.swf",
        array(
         
'params' => array(
           
'height' => '140',
           
'width' => '420',
           
'bgcolor' => '#FFFFFF'
         
)
        )
      );
    break;
  }
}
?>

Problem

sweet_as_an_elf - December 19, 2008 - 20:42

That still doesn't seem to work for me... although there was a syntax error. The revised correct code should read like this:

<?php
function  ubiquity_preprocess(&$vars, $hook) {
  switch(
$hook) {
    case
'page' :
     
$vars['swf_logo'] = "http://www.yoursite.com/files/images/banner.swf";
        array(
         
'params' => array(
           
'height' => '140',
           
'width' => '420',
           
'bgcolor' => '#FFFFFF'
         
)
        )
      ;
    break;
  }
}
?>

without the php opening and closing tags (since this is supposed to go in template.php).

When I insert

<?php
print $swf_logo
?>
inside the <div id="header-inner"> tags of the page.tpl file, my banner doesn't show up. What I doing wrong? Oh yeah, I'm also using the Ubiquity theme.

I can see that I has left

jokerejoker - December 21, 2008 - 18:51

I can see that I has left out the most important code of them all, the call to the swf() function that will get it all to work.

Your will her get the right code to fix your problem :)

<?php
function  themeName_preprocess(&$vars, $hook) {
  switch(
$hook) {
    case
'page' :
     
$vars['swf_logo'] = swf("http://www.yoursite.com/files/images/banner.swf",
        array(
         
'params' => array(
           
'height' => '140',
           
'width' => '420',
           
'bgcolor' => '#FFFFFF'
         
)
        )
      );
    break;
  }
}
?>

and the in yout page.tpl.php file print the $swf_logo variable

<?php
print $swf_logo;
?>

I apologies for the error

with views node feed

asanchez75 - February 16, 2009 - 04:20

This an example about how to use swftools with views_node_feed module.

Inside template.php

function  _phptemplate_variables($hook, $vars) {
         $vars['swf_logo'] = swf(
    "http://myweb.com/sites/all/themes/mytheme/imagerotator.swf",
    array('width' => '970', 'height' => '220', 'bgcolor' => '#336699'), array('file' => 'http://myweb.com/header/node_feed', 'showicons' => 'false', 'shownavigation' => 'false'),
    array('html_alt' => '<h1>Name of site if flash is disabled.</h1>')
  );
 
   return $vars;
}

A example of code for XML that is referenced toward imagerotator.swf

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<title>peru trekking hiking climbing</title>
<creator>Author 1</creator>
<location>http://myweb.com/files/peru_hiking_trekking _tours.jpg</location>
<info>Perú</info>
</track>
<track>
<title>peru_trekking_in_peru</title>
<creator>Author 2</creator>
<location>http://myweb.com/files/Hiking in Peru.jpg</location>

<info>Perú</info>
</track>

</trackList>
</playlist>

 
 

Drupal is a registered trademark of Dries Buytaert.