Text sources

From PhiWiki
Jump to: navigation, search
Datasources.png

You can choose between different text sources for any text based element in Phi.

Check the Parse text option if the text (of any output) contains Phi variables.

If you check Do NOT cache text the text is always read again for every client request from the selected source. This is always true for the database source.

Static

This is the default option and also the fastest one. Text will be displayed as entered.

Translated

The text depends on the currently choosen language of the browser.

If the returned text of a translation for a requested language is empty the 'C' text is used.

See also: Defining available languages for your page, document.languages, phi.lang.

Database

Textsourcedb.png

The text is read from a database query. Currently it is not possible to use translated text in the Template field. However this is on the list for future releases.

Use $PHISQL[x] (with 'x' as the position) to reference the values of the result set of the given SELECT statement.

If you need translated text, you can handle this via JavaScript in the server environment.

sql.query( 'SELECT firstname, lastname FROM person WHERE id='+request.post.pid );
if ( sql.next ) {
  var transtext=document.getElementById( 'translatedtext' );
  var template='Hello '+sql.value( 0 )+' '+sql.value( 1 )+'\n'+transtext.value;
  transtext.value=template;
}

Use the Header and Footer section to add text or tags (for example creating a table).

See also: Database support, Sql class.

File

You can load text directly from files (relatively to the document root) and even from different character encodings. If you specify a 'C' in the file path the 'C' will be replaced by the current used language.

See also: File translations, Supported encodings.

Url

Text can also be loaded from an external URL. This could be time consuming if you are not caching the text (see above notice about caching).

If a HTTP response header with Content-Type and charset= is provided the text is encoded with this charset. Otherwise UTF-8 is assumed.

Warning: Do NOT use URLs on the same localhost or this could lead in infinite recursion.

Process

You can use text from the output of a system process. Simply specifiy the path to the external program. The attributes list may contain Phi variables which are substituted before the process is started.

For the outputed text UTF-8 is assumed. If you need a different codec you can use JavaScript in the server environment instead:

var text=system.exec( 'myprogram', attributes, 'latin1' );

See also: system.exec().