User Tools

Site Tools


how_to_create_a_view

How To Create A View

The look or layout of pages are usually unique to each and every template. That's when separating HTML from the PHP logic becomes handy.

This is how simple it is to create a new view that can be uniquely styled within each template:

<?php
 
  $_myview = new ent_view();
 
  $_myview->snippets = [
    'title' => 'Hello World',
    'content' => 'Lorem ipsum dolor',
  ];
 
  echo $_mypage->stitch('subdirectory/myview');
?>

Here is an example of a template view file:

includes/templates/mytemplate.catalog/subdirectory/myview.inc.php
<main id="content">
  <h1><?php echo $title; ?></h1>
  <p><?php echo $content; ?></p>
</main>

Any snippet can be retrieved by one of the following syntax, depending on when most suitable:

  • <?php echo $parameter; ?>
  • {snippet:parameter}

If a {snippet:parameter} is not defined it can be inserted later by a value from a parent view. LiteCart will clean up any remaining snippets after rendering the page.

how_to_create_a_view.txt · Last modified: 2022/01/08 23:25 by tim