Home · Modules · Classes · Namespaces · Functions

QxtHtmlTemplate Class Reference
[QxtWeb module]

The QxtHtmlTemplate class provides a basic HTML template engine More...

    #include <QxtHtmlTemplate>

Inherits QMap<QString, QString>.

Public Functions


Detailed Description

The QxtHtmlTemplate class provides a basic HTML template engine

open a file containing html code and php style variables. use the square bracket operators to assign content for a variable

    QxtHtmlTemplate index;
    if(!index.open)
            return 404;
    index["content"]="hello world";
    echo()<<index.render();

the realatet html code would look like:

    <html>
    <head>
            <title>Test Page</title>
    </head>
            <?=content?>
    </html>

funny storry: whe are using this class to make our documentation (eat your own dogfood, you know ;). but when we where parsing exactly this file you read right now the first time, QxtHtmlTemplate got stuck in an infinite loop. guess why. becouse of that example above :D So be warned: when you assign content to a variable that contains the variable name itself, render() will never return.


Member Function Documentation

QxtHtmlTemplate::QxtHtmlTemplate ()

Constructs a new QxtHtmlTemplate.

void QxtHtmlTemplate::load ( const QString & d )

Loads data d.

bool QxtHtmlTemplate::open ( const QString & filename )

Opens filename. Returns true on success and false on failure. Note that it will also return false for an empty html file.

QString QxtHtmlTemplate::render () const

Uses the variables you set and renders the opened file. returns an empty string on failure. Does NOT take care of not assigned variables, they will remain in the returned string


Copyright © 2007-2010 Qxt Foundation
Qxt 0.6.1