MediaWiki master
QuickTemplate Class Reference

PHP-based skin template that holds data. More...

Inherited by BaseTemplate.

Collaboration diagram for QuickTemplate:

Public Member Functions

 __construct (Config $config=null)
 
 deprecate (string $name, string $version)
 Sets a template key as deprecated.
 
 execute ()
 Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
 
 extend ( $name, $value)
 extends the value of data with name $name with the value $value
 
 get ( $name, $default=null)
 Gets the template data requested.
 
 getHTML ()
 Fetch the output of a QuickTemplate and return it.
 
 getSkin ()
 Get the Skin object related to this object.
 
 html ( $str)
 
 msg ( $msgKey)
 
 set ( $name, $value)
 Sets the value $value to $name.
 

Public Attributes

array $data
 

Protected Member Functions

 haveMsg ( $msgKey)
 
 text ( $str)
 

Protected Attributes

Config $config
 

Detailed Description

PHP-based skin template that holds data.

Modern usage with returned output:

class MyTemplate extends QuickTemplate {
    public function execute() {
        $html = 'Hello, ' . Html::element( 'strong', [], $this->get( 'name' ) );
        echo $html;
    }
}
$tpl = new MyTemplate();
$tpl->set( 'name', 'World' );
$output = $tpl->getHTML();

Classic usage with native HTML echo:

class MyTemplate extends QuickTemplate {
    public function execute() { ?>

        Hello, <strong><?php $this->text( 'name' ); ?></strong>

    <?php
    }
}
$tpl = new MyTemplate();
$tpl->set( 'name', 'World' );

$tpl->execute(); // echo output

QuickTemplate was originally developed as drop-in replacement for PHPTAL 0.7 (http://phptal.org/).

Stability: stable
to extend

Definition at line 61 of file QuickTemplate.php.

Constructor & Destructor Documentation

◆ __construct()

QuickTemplate::__construct ( Config $config = null)
Parameters
Config | null$config

Definition at line 78 of file QuickTemplate.php.

References $config, and wfDebug().

Member Function Documentation

◆ deprecate()

QuickTemplate::deprecate ( string $name,
string $version )

Sets a template key as deprecated.

Access: internal
only for usage inside Skin and SkinTemplate class.
Parameters
string$name
string$versionWhen it was deprecated e.g. 1.38

Definition at line 94 of file QuickTemplate.php.

◆ execute()

QuickTemplate::execute ( )
abstract

Main function, used by classes that subclass QuickTemplate to show the actual HTML output.

Referenced by getHTML().

◆ extend()

QuickTemplate::extend ( $name,
$value )

extends the value of data with name $name with the value $value

Since
1.25
Parameters
string$name
mixed$value

Definition at line 113 of file QuickTemplate.php.

◆ get()

QuickTemplate::get ( $name,
$default = null )

Gets the template data requested.

Since
1.22
Parameters
string$nameKey for the data
mixed | null$defaultOptional default (or null)
Returns
mixed The value of the data requested or the default

Definition at line 144 of file QuickTemplate.php.

◆ getHTML()

QuickTemplate::getHTML ( )

Fetch the output of a QuickTemplate and return it.

Since
1.23
Returns
string

Definition at line 213 of file QuickTemplate.php.

References execute().

◆ getSkin()

◆ haveMsg()

QuickTemplate::haveMsg ( $msgKey)
protected
Parameters
string$msgKey
Returns
bool

Definition at line 193 of file QuickTemplate.php.

References wfMessage().

◆ html()

QuickTemplate::html ( $str)
Parameters
string$str

Definition at line 168 of file QuickTemplate.php.

◆ msg()

QuickTemplate::msg ( $msgKey)
Parameters
string$msgKey

Reimplemented in BaseTemplate.

Definition at line 176 of file QuickTemplate.php.

References text(), and wfMessage().

◆ set()

QuickTemplate::set ( $name,
$value )

Sets the value $value to $name.

Parameters
string$name
mixed$value

Definition at line 103 of file QuickTemplate.php.

◆ text()

QuickTemplate::text ( $str)
protected
Parameters
string$str

Definition at line 159 of file QuickTemplate.php.

Referenced by msg().

Member Data Documentation

◆ $config

Config QuickTemplate::$config
protected

Definition at line 70 of file QuickTemplate.php.

Referenced by __construct().

◆ $data

array QuickTemplate::$data

Definition at line 67 of file QuickTemplate.php.


The documentation for this class was generated from the following file: