Custom Content
One of the most powerful features of Exponential 3 is that you can define your own content classes.
A content class defines the structure of the content you want to publish on your site. Examples of
different content classes are; article, folder, image, product and link.
Creating classes
When you start to build your site you need to find the suitable structure for your content. Exponential
comes with a set of standard content classes which you can use, but you will most likely need to create
your own custom classes for your specific needs.
Lets say we need to publish information about cars. We then need to create a class called car.
The class needs the attributes; Name, Manufacturer, Model, Year, Description and Image.
You will find the administration interface for classes under "Set up" in the Exponential administration
interface. Then click on the appropriate group, e.g. content, where you want to place your class. The group
is just a method of categorizing your content classes for simpler administration of larger sites. Then you
click on the "New class" button. You will then be presented to the class edit window as shown below:
A class has three built-in attributes, in addition to the attributes you can add, edit and delete to
customize your class. The built-in attributes are object name, identifier and name. The name is the human
readable name for the class. The identifier is a string representation of the name, consisting only of the
characters 0-9 and a-z. It is used in templates, imports/exports etc. as an identifier for the class. The
object name defines how an object of this class will be named. All objects get a one-line name which can be
built up from several attributes, and contain arbitrary text. In this example it will be the same as the
first attribute - name. (For a User class, for instance, it would be natural to let the object name consist
of the attributes First Name and Last Name.)
Attributes
We then need to create the attributes for the car class. To add a new attribute you select the datatype
for the attribute in the dropdown in the lower right corner of the class edit page. Every attribute has a
name and an identifier. You only need to fill in the name, the identifier will automatically be generated.
Attributes are by default searchable, this means that the data entered here will be indexed in the search
engine. You can also select if the attribute is required or not. Additionally some datatypes have additional
settings, like default value and max string length for text line.
For our car class we will create datatypes of "Text line", "XML text" and image.
- Name: Text line
- Manufacturer: Text line
- Model: Text line
- Year: Text line
- Description: XML text
- Image: Image
Now that we've created all our attributes we can just click on the store button and our class is ready to use.
Note: To make objects of the new class available to anonymous users you must edit the Anonymous role,
as this role has specified access limitation by class by default.
Creating content
To take our newly created class for a spin we click on the content menu in the administration interface. You then
browse to a suitable placement and select "New car". This will bring us to the object edit window shown below. Here
you fill in all the values you want for you car and click "Send for publishing".
Now we've already published our own custom content without changing any code just clicking in the web interface.
When we view our newly created it will display with the standard templates as shown below:
Custom template
Note: When developing templates you should disable the view cache. When this is
enabled, the template engine does not check the modification date of the templates,
thus you will not see any changes. Edit settings/site.ini and set ViewCaching=disabled
in [ContentSettings].
The standard template is not how we want our car to be displayed at our webpage. Now we need to get our hands dirty, and create
a display template. To create a specific we need to figure out the ID of our class. The ID is a unique number which
represents our class. This can be found in the class list under "Set up -> classes". In my case this was 26.
To make Exponential understand that you want to have a custom template for your newly created class you must
create an override template for this. You can do this by creating a file in the Exponential root. The Exponential
root is the main folder of your Exponential installation. There you will see the sub folders, lib, kernel, design etc.
The file should be created under the design folder:
Unix:
design/standard/override/templates/node/view/full_class_26.tpl
Windows:
design\standard\override\templates\node\view\full_class_26.tpl
Note: If you don't have the subfolders override/templates/node/view, these must be created under your design folder
( which is design/standard/ as default ).
This file is a plain text file which you can edit with your favourite text editor, e.g. vi, emacs and notepad.
It must be a plain text editor with no formatting, so you cannot use word processors like word or open office.
Replace standard with your current design folder and 26 with the ID of your class.
This .tpl file is a Exponential 3 template file and is a combination of XHTML and
eZ template syntax. The example below shows a simple customisation where we place the
attributes in a table and have a large image under the page title.
<h1>{$node.name}</h1>
{attribute_view_gui attribute=$node.object.data_map.image}
<table>
<tr>
<td>
Manufacturer:
</td>
<td>
{attribute_view_gui attribute=$node.object.data_map.manufacturer}
</td>
</tr>
<tr>
<td>
Model:
</td>
<td>
{attribute_view_gui attribute=$node.object.data_map.model}
</td>
</tr>
<tr>
<td>
Year:
</td>
<td>
{attribute_view_gui attribute=$node.object.data_map.year}
</td>
</tr>
</table>
{attribute_view_gui attribute=$node.object.data_map.description}
In the example above you see that we use the template variable {$node} whenever we want
to fetch some data from our object. The node represents the specific placement of our object.
E.g. if it's published under /frontpage/news/ that will be a node. We can fetch the
object name using {$node.name}. This is the automatically generated name for the object which
we configured to be equal to the attribute: name. The function {attribute_view_gui } is a template
function used for fetching the content of a specific attribute. You use the attribute identifier
to specify the attribute.
The image below shows our car using the custom template.
|