Ignore:
Timestamp:
Sep 9, 2008, 11:53:31 AM (16 years ago)
Author:
rvelices
Message:
  • fix typing error in index.tpl
  • added template smarty function known_script (e.g.{known_script id="x" src"y.js"}) - useful to avoid double inclusion of a script such as prototype,jquery,... when a template and plugin need it independently (see the use in admin.tpl for example)
  • removed unused themeconf.template_dir
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/template.class.php

    r2502 r2513  
    6363    $this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') );
    6464    $this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
     65    $this->smarty->register_function('known_script', array(&$this, 'func_known_script'), false );
    6566    $this->smarty->register_prefilter( array('Template', 'prefilter_white_space') );
    6667    if ( $conf['compiled_template_cache_language'] )
     
    340341  }
    341342
     343 /**
     344   * This smarty "known_script" functions allows to insert well known java scripts
     345   * such as prototype, jquery, etc... only once. Examples:
     346   * {known_script id="jquery" src="{$ROOT_URL}template-common/lib/jquery.packed.js"}
     347   */
     348  function func_known_script($params, &$smarty )
     349  {
     350    if (!isset($params['id']))
     351    {
     352        $smarty->trigger_error("known_script: missing 'id' parameter");
     353        return;
     354    }
     355    $id = $params['id'];
     356    if (! isset( $this->known_scripts[$id] ) )
     357    {
     358      if (!isset($params['src']))
     359      {
     360          $smarty->trigger_error("known_script: missing 'src' parameter");
     361          return;
     362      }
     363      $this->known_scripts[$id] = $params['src'];
     364      $content = '<script type="text/javascript" src="'.$params['src'].'"></script>';
     365      if (isset($params['now']) and $params['now'] and empty($this->output) )
     366      {
     367        return $content;
     368      }
     369      $repeat = false;
     370      $this->block_html_head(null, $content, $smarty, $repeat);
     371    }
     372  }
     373
    342374  /*static */ function prefilter_white_space($source, &$smarty)
    343375  {
Note: See TracChangeset for help on using the changeset viewer.