[development] From Michelle: Request to themers.

Jerad Bitner sirkitree at gmail.com
Mon Dec 17 14:35:18 UTC 2007


Here's another fun one Nate Haug showed me. Keep your vars separated into
.vars.php files and only loads what is needed depending on the hook:

<?php
/**
 * Intercept template variables
 *
 * @param $hook
 *   The name of the theme function being executed
 * @param $vars
 *   A sequential array of variables passed to the theme function.
 */
function _phptemplate_variables($hook, $vars = array()) {
  global $user;

  $vars['user'] = $user;
  $vars['path'] = base_path() . path_to_theme() .'/';
  $vars['admin'] = $user->roles[3] || $user->uid == 1 ? TRUE : FALSE;
  $vars['moderator'] = $user->roles[4] ? TRUE : FALSE;
  $vars['editor'] = $user->roles[5] ? TRUE : FALSE;
  $vars['authenticated'] = $user->uid ? TRUE : FALSE;

  // Include broad variables for each hook.
  if (file_exists($vars['directory'] .'/'. $hook .'.vars.php')) {
    include_once $vars['directory'] .'/'. $hook .'.vars.php';
    $function = 'myplay_theme_variables_'. str_replace('-', '_', $hook);
    $vars = $function($vars);
  }

  // Specific variables for node types.
  if ($hook == 'node') {
    if (file_exists($vars['directory'] .'/node-'. $vars['node']->type
.'.vars.php')) {
      include_once $vars['directory'] .'/node-'. $vars['node']->type
.'.vars.php';
      $function = 'myplay_theme_variables_node_'. $vars['node']->type;
      $vars = $function($vars);
    }
  }

  return $vars;
}
?>

On Dec 16, 2007 10:35 PM, Larry Garfield <larry at garfieldtech.com> wrote:

> On Sunday 16 December 2007, Anton wrote:
> > On 17/12/2007, Michelle Cox <mcox at charter.net> wrote:
> > > Now that is a _great_ idea! I'll put that down in the readme as an
> option
> > > if they aren't able to do the merge. Thanks!
> > >
> > > Michelle
> >
> > Along similar lines, have you seen this method:
> >
> > http://drupal.org/node/152426
> >
> > It might be slightly more generic and easy to use for newbies.
>
> Fascinating.  I've recently started doing this in my themes:
>
> http://drupal.org/node/201587
>
> Many ways to skin this cat, it seems. :-)
>
> --
> Larry Garfield                  AIM: LOLG42
> larry at garfieldtech.com          ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the
> possession
> of every one, and the receiver cannot dispossess himself of it."  --
> Thomas
> Jefferson
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20071217/dfaa45ca/attachment.htm 


More information about the development mailing list