Tempo – 4.Class Methods

Classify of class methods

The implemented methods are:

# Whole template contents

  • Tempo()
  • parse(string $template_handle, string $template_file)
  • parse_str(string $template_handle, string $template_string)
  • clear(string $template_handle)

# BLOCK element

  • assign([array $loop_data])
  • loop(string $name)
  • attribute(string $name [, string $value])
  • style(string $name [, string $value])
  • tempo(string $name [, string $value])

Class methods of whole template contents

< Process of whole template contents >

Tempo()

Tempo() creates a new template object. Called via new, returns a newly allocated template object.

parse(string $template_handle, string $template_filename)

Parse the template contents(file). First parameter is the template handle corresponding the template contents to be processed. Second parameter is the template filename. When the file is loaded, it is parsed.

parse_str(string $template_handle, string $template_string)

Parse the template contents(string). First parameter is the template handle corresponding the template contents to be processed. Second parameter is the template string to be parsed.

for example:

< PHP coding >

clear(string $template_handle)

clear() clear the parsed contents. Using method close() isn’t usually necessary, the parsed contents is automatically cleared at the end of the script’s execution.

Class methods of BLOCK element

assign([array $loop_data])

This method inserts the values of all the variables that assigned the PHP global variables into the template. It will return the template contents that has been set variables. The returned value is able to be printed to STDOUT via print or echo.

< PHP coding >

First parameter of assign() is the data in the array for loop block. This method takes an array (which has to be in the format described below) and automatically substitutes the variables of a loop block(ex:table row) in template contents for the loop data.

1st index is the row number of loop, starting at zero. 2nd index is the column name of loop. The detailed usage for loop data refers to the ‘Example – Repeat Block’ section.

loop(string $name)

For each loop, the local variable is set to the current loop data. You use loop local variables to access information about the current loop (such as the loop index). The loop local variables is only accessible through the built-in member loop().

  • index – loop index, starting from zero.
  • data – current loop data.
  • groups – the number of group.
  • rows – the number of row.
  • fields – the number of field.

For example,

< Template contents : tempo.sample.htm >

< PHP code >

< Result >

attribute(string $name [, string $value])

This method get or set HTML tag attribute.

style(string $name [, string $value])

This method get or set HTML tag style.

tempo(string $name [, string $value])

This method get or set the value of tempo attribute statements.

< Template contents for BLOCK element >

< Process of BLOCK element >

< Result >

답글 남기기