Changing the Look and FeelChange the way your application looks by adding custom headers, footers, and sections, and by overriding the default templates with your own custom templates.
A generic Xataface application provides a reasonably good look and feel for a lot of applications. However, most applications still require some customizations. Most applications will want to have its own logo displayed at the top (instead of the Xataface logo), and quite often a custom footer is required also. Xataface allows for this form of customization as well as many other fine-grained modifications to the user interface via custom templates and delegate classes. Before we beginMost of your customizations will necessitate the use of custom templates. For this our application will need a 'templates' directory to store the templates, and a 'templates_c' directory to store the compiled templates (since Smarty template engine is used for processing the templates, and it needs a directory to store the compiled versions). So, before we begin our customizations, we need to make sure that these directories exist, and that the 'templates_c' directory is writable by the web server (e.g. chmod 0777). Our application's directory structure should resemble the following:
Although, please disregard the 'install' directory and the 'README.txt' file. They have been added to store extra information about this tutorial. The crucial additions are the 'templates' and 'templates_c' directories. Xataface templates
Xataface handles all of its look and feel using Smarty templates. They are all stored in the Dataface/templates directory. A quick glance at the contents of this directory will give you an idea of what templates are available. Some templates display a whole page, while others simply show a section of a page. Some of the more notable templates include:
For a more thorough treatment of Xataface's core templates, see "Tour of Xataface's Core templates" in the Xataface Customization tutorial. Overriding templatesTo change the contents of any given template in the Dataface/templates directory, all we have to is copy the template into our application's 'templates' directory, and make the desired changes. The new template will be used instead of the default template. In general, to override a given template, just add a template of the same name to the application's 'templates' directory. Example 1: Changing the logoThe Xataface logo is nice, but our application should probably have a custom logo that says "Faculty of Widgetry" or something to that effect. We will do this by completing the following steps:
Now we can load the application in a web browser and see our new logo in place of the old Xataface logo.
Inserting content into blocks and slots
The above example, where we overrode the Dataface_Logo.html template, works well only in a select few situations. Most of the time we don't want to override an entire template. We just want to add some content to it or change it a little bit. Most of Xataface's templates contain placeholders called "blocks" and "slots" for you to be able to add your own content. As an example, let's look at some of the source for the Dataface_Main_Template.html template <table width="100%" border="0" cellpadding="5" id="main_table"> This is the little bit of markup that produces the left column of the main table in the Xataface application. The content inside the curly braces are template markup tags that have meaning. Take special notice of the {block} and {define_slot} tags. These allow you to add your own content to this template via your delegate classes. A {block} tag will display custom content provided by your delegate classes. The {define_slot} tag will show your custom content, if it is available - OR - it will display the contents that lie between the {define_slot} and {/define_slot} tags. Example: Adding a side-bar to show the courses for the current programLet's say we want to add a side bar so that when we view a Program record, we can easily see the courses in that program. We will do this by "inserting" content into the "before_left_column" block in the main template shown above. We need to add a delegate class to the 'Program' table in order to make this happen, so we create the file tables/Program/Program.php with the following content: <?php
Note that it is not good form to embed HTML inside echo statements as we did in this example. A much more elegant solution would involve the creation of a template that is called from the block__before_left_column() method. So to insert content into the {block name="before_left_column"} tag, we just implement a method named "block__before_left_column". in general. The above example makes use of the Xataface API. You can look up any class or function call using the API docs at http://dataface.weblite.ca. Now we can load our application, and select the "Program" tab to view one of our "Program" records - and notice our new side bar:
Also notice that this sidebar only appears in the "Program" table (If you click the "Course" tab, this sidebar will disappear). This is because we defined the method in the "Program" table delegate class. Source files downloadDownload the source files for the Faculty of Widgetry Application From here...This section has given you just a brief glimpse of the Xataface's templating capabilities. The rabbit hole goes much deeper, however. For a more in-depth exploration of the subject, please refer to the following pieces of documentation:
|