JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > Themes and Templates > Extending Themes
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  Extending Themes
Added by scud, last edited by scud on Apr 29, 2006  (view change)
Labels: 
(None)

有时你可能想要在一个已存在的theme里简单地覆盖一个模板(查看Template Loading)或者创建一个可选的模板.然而,其他时候你可能想要创建你自己的整个theme,特别是你计划为你的组织构建一个丰富的唯一的并且可复用的一套模板时.

有三种方法来创建一个新的theme:

  • 白手起家,从头创建一个新的theme (困难!)
  • 扩展一个已存在的theme
  • 包装一个已存在的theme

我们永远不会推荐从头创建一个新的theme.更恰当地说,我们相信simple theme提供了为你扩展或者包装需要的足够的基本要素,从而来创建你自己唯一的theme.不管你选择了那个方法(经常情况下你最终两种方法都用了一些,因为它们不是互斥的),我们 强烈 建议你解压 WebWork的jar,并查看所有提供的theme的原有的模板.这会让你好好理解如何制造你自己的模板和theme.

包装一个存在的Theme

看一下xhtml theme,我们可以看到模板中广泛引用了 wrapping (包装)技术.例如,一个模板可能是这样的:

<#include "/${parameters.templateDir}/xhtml/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/xxx.ftl" />
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />

这个模板简单地使用一个header和一个footer包装了simple theme的已存在的模板.这是一种强大的方法,来在simple theme提供的基本的HTML元素外围增加额外的行为.

扩展一个存在的Theme

WebWork提供的theme基础设施也允许theme来 扩展 一个存在的theme. 这意味着一个theme可以包含一个 theme.properties ,其中有一个 parent 设置,包含了你想要扩展的theme的名字.例如,ajax theme就是用这种方式扩展xhtml theme的.

扩展一个theme,你不需要实现Tags里用到的每个模板.也就是说,你只需要实现你希望覆写的模板.其他的模板将从parent模板中装载.

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators