The dataset and HDF Files
此内容尚不支持你的语言。
It is often convenient to load elements of a dataset from disk. Normally data is loaded from a ClearSilver file format called HDF, although it could easily be loaded from XML or another format. HDF stands for Hierarchical Data Format (yes, another HDF). It supports two different syntax for representing the dataset hierarchy which can be intermixed arbitrarily. The first is a simple dotted path scheme:
Page.Name = My IndexPage.URL = /myindex.htmlPage.Menu.0 = HomePage.Menu.1 = PreferencesPage.Menu.2 = HelpPage.Menu.3 = SupportThe second is a nested elements scheme:
Page { Name = My Index URL = /myindex.html Menu { 0 = Home 1 = Preferences 2 = Help 3 = Support }}The hierarchy within an HDF file can be arbitrarily nested and contain any data elements desired. For instance, to extend the format of the Menu above, we could add:
Page { Menu { 0 { Name = Home URL = / } 1 { Name = Preferences URL = /prefs } 2 { Name = Help URL = /help.html } 3 { Name = Support URL = /feedback/ } }}Because APIs for HDF support reading and writing files in these formats, HDF can serve as a great configuration or persistence language. However, its primary purpose here is to load static elements into the dataset for use in a ClearSilver template.
When a ClearSilver template is rendering, it can reference specific variables in the dataset or iterate over all of the elements at a specific point in the dataset hierarchy. For example, a CS template which was rendering the HDF dataset above might iterate over Page.Menu, rendering each menu item’s .Name and .URL elements.
There are two more important parts of the HDF file syntax.
- A name can copy the contents of another name by using a colon instead of an equals sign. For example,
This means thatPage.Name : Page.Menu.0.Name
Page.Nameis the same asPage.Menu.0.Name. Note thatPage.Menu.0.Namehas to be defined before you can copy it intoPage.Name. - A name can be set to a multi-line string value. This uses a syntax similar to standard UNIX shell/Perl syntax. For example:
Page.Name << EOMThis is my multi-line page name.Isn't it spiffy?EOM

