From ATK Wiki

Revision as of 10:38, 12 February 2010 by Ivo (Talk | contribs)
Jump to: navigation, search

Attribute: atkDocumentAttribute

API docs | Flags

List of other attributes

atkDocumentAttribute screenshot



This page sets out how to use the atkDocumentAttribute. This attribute is a special attribute within ATK as it does not relate to any database field. This attribute is used to create a document (currently in the open document format - odt) which uses the data within the nodes other attributes to fill a template of the desired document.


The following text is straight out of the ATK 5.5.0 configuration file located in the root directory of the atk demo application.

  // -------------- DOCUMENT WRITER CONFIGURATION ---------------
  // For document attributes, ATK automatically searches for template
  // documents in a specific directory. The base directory to search in
  // can be specified below. The document templates must be put in a
  // specific directory structure under this base directory: first of all
  // a subdirectory must be made for every module for which you want to
  // include document templates (equal to the modulename of that module, as
  // set in Then a subdirectory in that directory must be
  // made according to the name of the node for which you want to include
  // document templates. In this subdirectory you can put your document
  // template files. So if you have $config_doctemplatedir set to
  // "doctemplates/", then you can put your documents in
  // "doctemplates/modulename/nodename/".
  $config_doctemplatedir = "doctemplates/";

Constructor Code

To include a document attribute within your node then add the following code to the constructor function of the node class file:

class samplenode extends atkNode
    public function __construct()
        $this->add(new atkDocumentAttribute("documents"));

When using atkMetaNodes, use the following:

class sampleNode extends atkMetaNode
    public function postMeta()
        $this->add(new atkDocumentAttribute("documents"));   

When you load this node in the webpage you will now see an extra column named the same as the attribute name (in the example "Open Document". In addition the attribute will have looked in the directory "doctemplates/samplemodule/samplenode/" for any suitable template documents and include them in a dropdown list with an "open" button alongside the list box.

Assign Document Variables

To place the variables of the node attributes into the template file simply create a new document within OpenOffice (a free and open source office application that uses the open document format as standard). Once in the file position the cursor where you would like the variable to be and type [name] where "name" is the name given to an attribute within the node. If you require a label in addtion to the data value for the record then use [name_label] and it will return the label as defined in the default logic (or using any display overide defined in the node class file). This should also respect any language file created for the node/application.

All of the above magic happens within the document handler function which is used whenever the document action is requested. The above logic only works for attributes which are within the same node as the Document Attribute and does not work with relationship attributes.

In order to obtain data of attributes in a node linked by a m2o or o2m relationship you have to overide a specific function (AssignDocumentVars()). Fortunately the code within the document action allows for an overide of this function to exist within the node class file. The way to overide this function is on the howto:


ATK Demo Application - Lesson 8

ATK API Documentation Look for atkDocumentAttribute and atkDocumentHandler

Personal tools