-
Notifications
You must be signed in to change notification settings - Fork 27
Formatting data
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];}
Transphporm currently supports the following formats for strings:
- uppercase
- lowercase
- titlecase
- nl2br
- html
Examples:
$xml = '
<h1> </h1>
';
$tss = 'h1 {content: "TeSt"; format: uppercase}';
$template = new \Transphporm\Builder($xml, $tss);
echo $template->output()->body;
Prints:
<h1>TEST</h1>
$xml = '
<h1> </h1>
';
$tss = 'h1 {content: "TeSt"; format: lowercase}';
$template = new \Transphporm\Builder($xml, $tss);
echo $template->output()->body;
Prints:
<h1>test</h1>
$xml = '
<h1> </h1>
';
$tss = 'h1 {content: "test"; format: titlecase}';
$template = new \Transphporm\Builder($xml, $tss);
echo $template->output()->body;
Prints:
<h1>Test</h1>
$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>
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>
Transphporm supports formatting numbers to a number of decimal places using the decimal
format. You can specify the number of decimal places:
$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>