Gallery: 外观主题:参考:Smarty:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
 
第1行: 第1行:
==Smarty==
==Smarty==
[http://smarty.php.net Smarty] is a PHP templating system which is used by Gallery2 to assemble the pages that are presented to the user.  Templates allow a great degree of customisation of Gallery2 by separating the design of its web pages from the code that is needed to make Gallery run.  By using a special markup language alongside standard HTML, customised themes can be created which display the core Gallery items in different ways.
[http://smarty.php.net Smarty]是一个PHP模板系统,被Gallery2用来收集显示给用户的页面。模板允许Gallery2的高度自定义--通过将其web页面的设计与Gallery允许所需的代码分离开。通过使用某种特殊的markup语言以及标准的HTML,就可自定义外观主题,从而以多种方式显示核心Gallery项目。


===Documentation and Tutorials===
===资料及教程===
Full documentation for the Smarty system is available on its web page at [http://smarty.php.net http://smarty.php.net].  There is also a crash-course to Smarty on the site, and there are many Smarty tutorials available on the web by searching.  
有关Smarty系统的完整资料请见[http://smarty.php.net http://smarty.php.net]。在网站上还有Smarty速成资料,而通过搜索引擎你可以找到很多Smarty的相关教程。  


===Using Smarty Templates===
===使用Smarty模板===
Smarty templates consist of a mix of HTML and Smarty markup language.  This allows them to display dynamic content, for example if you wished to display a welcome message to a user on your Gallery page you could use the following code in your page template:
Smarty模板混合有HTML和Smarty markup语言。这允许它们显示动态的内容。例如,如果你希望在Gallery页面上向某用户显示欢迎消息的话,你可以在页面模板中使用如下的代码:


<pre><p>Hello, <b>{$user.userName}</b></p></pre>
<pre><p>Hello, <b>{$user.userName}</b></p></pre>


To do the same as a plain HTML file would require a lot of effort in the PHP code that runs Gallery and would be a lot less customisable than using a separate template system.  Working knowledge of the following Smarty concepts and tags would be useful for writing theme templates for Gallery2:
而对于普通HTML文件,要达到相同的效果的话就需要在PHP代码上花很大功夫,而且所得结果的自定制性会比较差,也就是不如独立的模板系统。理解以下的Smarty概念及标记的话,在编写Gallery2的外观主题模板时能帮上不少忙:


*Writing Smarty templates using HTML and Smarty markup
*使用HTML和Smarty markup编写Smarty模板
*Variable access using <code>{$variableName}</code> syntax
*使用<code>{$variableName}</code>语法的变量访问
*Conditional statements using <code>{if}...{else}...{/if}</code>
*使用<code>{if}...{else}...{/if}</code>的条件语句
*Array access using <code>{foreach}...{/foreach}</code>
*使用<code>{foreach}...{/foreach}</code>的数组访问
*Object access using <code>{object->method}</code>
*使用<code>{object->method}</code>的对象访问


===Debugging Templates and Exploring Variables===
===模板debugging和变量的探索===
If Gallery2 debugging is turned on, Smarty will produce debug output every time it renders a template.  This output appears in a separate window and shows all of the variables used in the page, which can be invaluable in debugging a template when it doesn't work as expected.  It is also a useful way to view all of the variables passed into the template by Gallery2, particularly if you need to access theme or user information.
如果开启了Gallery2的debugging,每次渲染某模板时,Smarty都会产生debug输出。该输出出现在一个单独的窗口中并显示所有用在相应页面中的变量--当模板不按所预期的运行时这就非常有价值了。同样这帮助查看所有传送到模板的变量,尤其是当你需要访问外观主题或用户信息时这就更有用了。


To turn on Gallery2 debugging, you will need to edit the ''config.php'' file located in the root directory of your Gallery installation.  There is an explanation of Gallery2's debugging modes followed by a statement:
要打开Gallery2的debugging,你需要编辑Gallery根目录下的''config.php''文件。这里有一个关于Gallery2 debugging模式的解释:


<pre>$gallery->setDebug(false);</pre>
<pre>$gallery->setDebug(false);</pre>


To turn debugging on, change this line so that it reads:
要开启debugging模式,修改该行:


<pre>$gallery->setDebug('buffered');</pre>
<pre>$gallery->setDebug('buffered');</pre>


Save ''config.php'' and copy it back to the Gallery root directory.  When you now view any Gallery page, you will see the Gallery debug output at the bottom of the page, and the Smarty debug output should appear in a separate pop-up window.  If it does not, make sure that popups are allowed for your Gallery site.
保存''config.php''并将其复制到Gallery根目录下。现在当你查看任何Gallery页面时,就会在页面底部看到Gallery debug输出,而smarty debug输出应当出现在某个单独的他出窗口中。如果没有弹出窗口的话,请确保你允许Gallery站点弹出窗口。


===Making Data Available in a Template===
===使数据在模板中可用===
Some items of information are made available to a template as standard by Gallery2.  However, there are some items that have to be requested by your theme file before they will be accessible from the template. Typically this is done through the ''loadCommonTemplateData'' function call in the various <code>showXXX</code> functions in your ''theme.inc'' file. For a discussion of the options available, look at the source code for GalleryTheme.class which can be found in the Gallery's ''/modules/core/classes/' directory.
信息的某些项目被Gallery作为标准用于某模板。然而某些项目必须被外观主题请求了才能够由模本进行访问。这往往是通过''theme.inc''的各种<code>showXXX</code>函数中的''loadCommonTemplateData''函数呼叫完成的。有关可用选项的讨论,请参看GalleryTheme.class的源代码,可在Gallery的''/modules/core/classes/'目录中找到。


[[Category:Gallery 2:Development]]
[[Category:Gallery 2:Development]]

2008年9月25日 (四) 15:32的最新版本

Smarty[ ]

Smarty是一个PHP模板系统,被Gallery2用来收集显示给用户的页面。模板允许Gallery2的高度自定义--通过将其web页面的设计与Gallery允许所需的代码分离开。通过使用某种特殊的markup语言以及标准的HTML,就可自定义外观主题,从而以多种方式显示核心Gallery项目。

资料及教程[ ]

有关Smarty系统的完整资料请见http://smarty.php.net。在网站上还有Smarty速成资料,而通过搜索引擎你可以找到很多Smarty的相关教程。

使用Smarty模板[ ]

Smarty模板混合有HTML和Smarty markup语言。这允许它们显示动态的内容。例如,如果你希望在Gallery页面上向某用户显示欢迎消息的话,你可以在页面模板中使用如下的代码:

<p>Hello, <b>{$user.userName}</b></p>

而对于普通HTML文件,要达到相同的效果的话就需要在PHP代码上花很大功夫,而且所得结果的自定制性会比较差,也就是不如独立的模板系统。理解以下的Smarty概念及标记的话,在编写Gallery2的外观主题模板时能帮上不少忙:

  • 使用HTML和Smarty markup编写Smarty模板
  • 使用{$variableName}语法的变量访问
  • 使用{if}...{else}...{/if}的条件语句
  • 使用{foreach}...{/foreach}的数组访问
  • 使用{object->method}的对象访问

模板debugging和变量的探索[ ]

如果开启了Gallery2的debugging,每次渲染某模板时,Smarty都会产生debug输出。该输出出现在一个单独的窗口中并显示所有用在相应页面中的变量--当模板不按所预期的运行时这就非常有价值了。同样这帮助查看所有传送到模板的变量,尤其是当你需要访问外观主题或用户信息时这就更有用了。

要打开Gallery2的debugging,你需要编辑Gallery根目录下的config.php文件。这里有一个关于Gallery2 debugging模式的解释:

$gallery->setDebug(false);

要开启debugging模式,修改该行:

$gallery->setDebug('buffered');

保存config.php并将其复制到Gallery根目录下。现在当你查看任何Gallery页面时,就会在页面底部看到Gallery debug输出,而smarty debug输出应当出现在某个单独的他出窗口中。如果没有弹出窗口的话,请确保你允许Gallery站点弹出窗口。

使数据在模板中可用[ ]

信息的某些项目被Gallery作为标准用于某模板。然而某些项目必须被外观主题请求了才能够由模本进行访问。这往往是通过theme.inc的各种showXXX函数中的loadCommonTemplateData函数呼叫完成的。有关可用选项的讨论,请参看GalleryTheme.class的源代码,可在Gallery的/modules/core/classes/'目录中找到。