Files
thetempusproject/app/resources/views/example.html
2024-08-04 21:15:59 -04:00

142 lines
5.2 KiB
HTML

<p>It is comprised entirely of free form HTML</p>
<p>If you are feeling extra bold you can use the templating engine to set variables to be replaced at runtime such as {variable} or even {variable2}, or maybe even just look through some data:</p>
{loop}
{value1} is the first value.<br />
{value2} is the second value.<br />
{value3} is the third value.<br />
{/loop}
{ALT}No Loop{/ALT}
{footer}
<h1>This is a default view </h1>
<p>The Tempus-Project template-processor works with the backend to render html for the end user. This process has several steps and components that can get pretty complex. For the moment let's just review a few that can be used to generate web pages. </p>
<h2>Views</h2>
<p>Views are the most basic interaction between the front-end and back-end. Inside of a controler, you can call a view in two ways:</p>
<h3>1. Normal - Views::view</h3>
<pre></pre>
<h3>2. Inline - Views::simpleView</h3>
<pre></pre>
<h2>Components</h2>
<p>You can think of components as a sort of front-end variable that can be filled in by the back-end before being send to the end-user. You can include components in all template parsing with a simple command:</p>
<pre></pre>
Adding this to a controler will give access to that component's value in the rendering engine. For example:
<pre></pre>
<h2>Pagination</h2>
PAGINATION
if (Pagination::totalPages() <= 1) {
Components::set('PAGINATION', '<lb>');
} else {
Components::set('PAGINATION', Views::simpleView('nav.pagination', $pageData));
}
<h2>Navigation</h2>
<h2>Filters</h2>
<p>In some cases, you may want to hide or show text on a page conditionally. For example, you may have administrator controls on a commonly used page. Obviously you would like to hide those controls from regular users; even if you have safeguards to prevent them from performing any restricted actions.</p>
<p>This is where filters come in. They do exactly that, conditionally hide or show part of a page based on back-end logic. The admin example is so common, its already built in. If a user has the isAdmin permission on thier group, they will be able to see anything within the "ADMIN" tag:</p>
<pre>
Filters::add('member', '#{MEMBER}(.*?){/MEMBER}#is', (self::$isMember ? '$1' : ''), true);
Filters::add('mod', '#{MOD}(.*?){/MOD}#is', (self::$isMod ? '$1' : ''), true);
Filters::add('admin', '#{ADMIN}(.*?){/ADMIN}#is', (self::$isAdmin ? '$1' : ''), true);
</pre>
'#\[b\](.*?)\[/b\]#is' => '<b>$1</b>',
'#\[p\](.*?)\[/p\]#is' => '<p>$1</p>',
'#\[i\](.*?)\[/i\]#is' => '<i>$1</i>',
'#\[u\](.*?)\[/u\]#is' => '<u>$1</u>',
'#\[s\](.*?)\[/s\]#is' => '<del>$1</del>',
'#\[code\](.*?)\[/code\]#is' => '<code>$1</code>',
'#\[color=(.*?)\](.*?)\[/color\]#is' => "<font color='$1'>$2</font>",
'#\[img\](.*?)\[/img\]#is' => "<img src='$1'>",
'#\[url=(.*?)\](.*?)\[/url\]#is' => "<a href='$1'>$2</a>",
'#\[quote=(.*?)\](.*?)\[/quote\]#is' => "<blockquote cite='$1'>$2</blockquote>",
'#\(c\)#is' => '&#10004;',
'#\(x\)#is' => '&#10006;',
'#\(!\)#is' => '&#10069;',
'#\(\?\)#is' => '&#10068;',
'#\[list\](.*?)\[/list\]#is' => '<ul>$1</ul>',
'#\(\.\)(.*)$#m' => '<li>$1</li>',
'/(^|\s)@(\w*[a-zA-Z_]+\w*)/' => ' <a href="http://twitter.com/search?q=%40\2">@\2</a>',
'/(^|\s)#(\w*[a-zA-Z_]+\w*)/' => ' <a href="http://twitter.com/search?q=%23\2">#\2</a>',
'#/\*.*?\*/#s' => null,
'#(?<!:)//.*#' => null,
"#{CHECKED:(.*?)=(.*?)}#s" => null,
<h2>Issues</h2>
<p>One of the pre-existing filters happens to be Issues. In the controller for this file, you should see a block that includes several examples of Issues. These issues are automatically added as individual components and hidden with the issues filter.<p>
<pre>
Issues::add( 'error', [ 'This is an error with multiple parts.' => [ 'Error 1', 'Error 2' ] ] );
Issues::add( 'error', 'This is a single error.' );
Issues::add( 'success', [ 'This is a success with multiple parts.' => [ 'Success 1', 'Success 2' ] ] );
Issues::add( 'success', 'This is a single success.' );
Issues::add( 'notice', 'This is a single notice.' );
Issues::add( 'info', 'This is a single info.' );
Filters::add('issues', '#{ISSUES}(.*?){/ISSUES}#is', (Issues::hasIssues() ? '$1' : ''), true);
Components::set( 'NOTICE', $test );
Components::set( 'SUCCESS', $test );
Components::set( 'ERROR', $test );
Components::set( 'INFO', $test );
</pre>
<h2>Forms</h2>
select Radio
$selected = 'CHECKED:' . $fieldName . '=' . $value;
Components::set($selected, 'checked="checked"');
select Option
$find = "#\<option (.*?)value=\'" . $value . "\'#s";
$replace = "<option $1value='" . $value . "' selected";
self::$options[$find] = $replace;