Share » Learn » eZ Publish » Creating Datatypes in eZ Publish 4

Creating Datatypes in eZ Publish 4

Wednesday 21 May 2008 9:14:00 am

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

As was previously mentioned, we have templates for the editing and viewing of both the content class and the content object. This chapter explains how you can access attribute data inside the templates and describes the interaction between the PHP code and the templates. For more information on templates in general, please refer to the eZ Publish user manual.

Viewing the class attribute

Let's start with the most basic example, for viewing the class attribute in design/standard/templates/class/datatype/view/ymcdatetime.tpl. In this template we use the variable $class_attribute, which is automatically available for every class attribute template. The $class_attribute variable is an instance of eZContentClassAttribute.

For our simple case we only need the value of the “data_int1” attribute of our eZContentClassAttribute instance. This is the attribute that we used in the fetchClassAttributeHTTPInput method to store whether or not the input fields should be pre-filled with the current date. We access it simply with $class_attribute.data_int1.

Editing the class attribute

The only additional concept in the template for editing the class attribute in design/standard/templates/class/datatype/edit/ymcdatetime.tpl is how to build the name of our input field. It is made up as previously described:

ContentClass_ymcDateTime_default_{$class_attribute</span>.id}

First, there is a namespace “ContentClass”, then the name of the datatype “ymcDateTime”, the name of the input field “default” and at the end an ID for the attribute.

Viewing and editing the object attribute

I will skip discussing the object editing template (design/standard/templates/content/datatype/edit/ymcdatetime.tpl), since there is nothing new in it compared to the two templates already mentioned.

The template for viewing object attributes of our datatype is located at design/standard/templates/content/datatype/view/ymcdatetime.tpl. One thing to note is how we access each of the values that make up the DateTime object. Inside this template you see the construct {$attribute.content.day}, and equivalent constructs for the other values. Let's look at each of the elements in the construct for the “day” value.

First, eZ Publish has predefined an instance of eZContentObjectAttribute in the variable $attribute. However, we cannot simply access the value for the day in the next level since it is stored in an object. Therefore, we must access “content”, whereby eZ Publish calls the objectAttributeContent method of our datatype. The return value of this method is directly given back as the content attribute itself. Looking in our datatype source code, you see that we return an instance of ymcDatatypeDateTime as the return value of this method. This means that the last word “day” accesses the attribute method of ymcDatatypeDateTime with the parameter “day”. The return value of this attribute method is the value that we are looking for.

36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)