Skip to content
Chris Johnson edited this page Jul 8, 2016 · 11 revisions

Transphporm supports formatting of data as its output. The syntax for formatting is this:

h1 {content: "content of element"; format: [NAME-OF-FORMAT] [OPTIONAL ARGUMENT OF FORMAT];}

String formatting

Transphporm currently supports the following formats for strings:

  • uppercase
  • lowercase
  • titlecase
  • nl2br
  • html

Examples:

String format: uppercase

$xml = '
<h1> </h1>
';

$tss = 'h1 {content: "TeSt"; format: uppercase}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<h1>TEST</h1>

String format: lowercase

$xml = '
<h1> </h1>
';

$tss = 'h1 {content: "TeSt"; format: lowercase}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<h1>test</h1>

String format: titlecase

$xml = '
<h1> </h1>
';

$tss = 'h1 {content: "test"; format: titlecase}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<h1>Test</h1>

String format: nl2br

$xml = '
<p></p>
';

$tss = 'p {content: "test1\ntest2"; format: nl2br}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<p>test1<br/>test2</p>

String format: html

Whenever you use a content string, the content is escaped by replacing HTML entities unless you set format: html.

$xml = '<p></p>';

$tss = 'p {content: "<h1>My Title</h1>"; format: html}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<p><h1>test1</h1></p>

Number formats

Transphporm supports formatting numbers to a number of decimal places using the decimal format. You can specify the number of decimal places:

Number format: decimal

$xml = '
<h1> </h1>
';

$tss = 'h1 {content: "11.234567"; format: decimal 2}';

$template = new \Transphporm\Builder($xml, $tss);

echo $template->output()->body;

Prints:

<h1>1.23</h1>
Clone this wiki locally