Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

Chapter 16. 资�

模��以是����的���供的。 当你display() 或者 fetch()一个模�, �或者当你包�一个模�到�一个模�中的时候,你需��供一个资�类型�路径�模��。 如果没有明确指明资�类型,则将�定是使用 $default_resource_type (默认是“file�)。

文件资�

Smarty通常�行在内置的�基于文件系统的模�资�上。 默认资�是file:。 如果修改了$default_resource_type 那么资�关键字file:就必须�指明。

如果找�到需�的模�文件,那么 $default_template_handler_func将会被调用。

说明

在Smarty 3.1开始,除�开�了 $use_include_path�置,�则文件资��会��索 include_path 的路径了。

$template_dir目录

Smarty从$template_dir设置的目录中, 获�模�文件资�。 多个模�目录将以在数组中的顺�进行�索,在寻找到第一个匹�的模�时将返回。

Example 16.1. 使用$template_dir


<?php
$smarty->display('index.tpl');
$smarty->display('file:index.tpl'); // �上
?>

   

模�中使用


{include file='index.tpl'}
{include file='file:index.tpl'} {* �上 *}

   

特定的$template_dir

Smarty 3.1 �供“归类符���定义$template_dir中的特定元素。 此特性��许网站中使用和更好地管�多个模�集�。

“归类符���以用在任何定义了file:资�类型的地方。

Example 16.2. 特定的$template_dir


<?php

// 设置模�目录
$smarty->setTemplateDir(array(
    './templates',            // element: 0, index: 0
    './templates_2',          // element: 1, index: 1
    '10' => 'templates_10',   // element: 2, index: '10'
    'foo' => 'templates_foo', // element: 3, index: 'foo'
));

/*
  �定模�目录结构如下:
  ./templates/foo.tpl
  ./templates_2/foo.tpl
  ./templates_2/bar.tpl
  ./templates_10/foo.tpl
  ./templates_10/bar.tpl
  ./templates_foo/foo.tpl
*/

// 正常读�
$smarty->display('file:foo.tpl'); 
// 将载入 ./templates/foo.tpl

// 默认使用数字下标
$smarty->display('file:[1]foo.tpl'); 
// 将载入 ./templates_2/foo.tpl

// 使用字符串的下标('10'看起��数字下标,但�是有�引�的字符串)
$smarty->display('file:[10]foo.tpl'); 
// 将载入 ./templates_10/foo.tpl

// 使用字符串的下标
$smarty->display('file:[foo]foo.tpl'); 
// 将载入 ./templates_foo/foo.tpl

// 使用 "未知" 数字下标 (用元素的数字)
$smarty->display('file:[2]foo.tpl'); 
// 将载入 ./templates_10/foo.tpl

?>

   

模�中调用


{include file="file:foo.tpl"}
{* 将载入 ./templates/foo.tpl *}

{include file="file:[1]foo.tpl"}
{* 将载入 ./templates_2/foo.tpl *}

{include file="file:[foo]foo.tpl"}
{* 将载入 ./templates_foo/foo.tpl *}

   

任�目录的模�

在$template_dir之外的模�, file:将需�使用�对路径�获�模�。

Note

当Security开�, 在$template_dir之外的模�是��许读�的,除�你将这些目录都设置在$secure_dir中。

Example 16.3. 任�目录的模�


<?php
$smarty->display('file:/export/templates/index.tpl');
$smarty->display('file:/path/to/my/templates/menu.tpl');
?>

   

模�中:


{include file='file:/usr/local/share/templates/navigation.tpl'}

   

Windows文件路径

如果使用Windows的机器,那么文件路径将以驱动盘符(C:)开头。 确�file:的路径��命�空间冲�,达到需�的结果。

Example 16.4. 使用windows的文件路径


<?php
$smarty->display('file:C:/export/templates/index.tpl');
$smarty->display('file:F:/path/to/my/templates/menu.tpl');
?>

  

在模�中:


{include file='file:D:/usr/local/share/templates/navigation.tpl'}


Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 17 plus 7? (Are you human?)

Advertisement