How To Create A New Page

Creating a new page in LiteCart is pretty simple. Basically just place a file in the pages folder and name it name.inc.php. The .inc in the extension prevents the file from being executed alone. The .php in the extension tells us this is PHP logic.

pages/mypage.inc.php:


<?php
  document::$snippets['title'][] = 'Your head title here';
  document::$snippets['description'] = 'Your meta description here';
?>
<h1>Hello World</h1>
<p>Lorem ipsum dolor...</p>

The page is then accessed by https://www.yourdomain.com/mypage

How To Create A New Page Using A View

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

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

pages/mypage.inc.php:


<?php

  document::$layout = 'default'; // Uses includes/templates/...catalog/layouts/default.inc.php to wrap the content of the page

  document::$snippets['title'][] = 'Your head title here';
  document::$snippets['description'] = 'Your meta description here';

  $_mypage = new ent_view();

  $_mypage->snippets = [
    'title' => 'Hello World',
    'content' => 'Lorem ipsum dolor',
  ];

  echo $_mypage->stitch('pages/mypage');  // Uses includes/templates/...catalog/pages/mypage.inc.php for content

Here is an example of a template view file:

includes/templates/mytemplate.catalog/pages/mypage.inc.php:


<main id="content">
  <h1><?php echo $title; ?></h1>
  <p><?php echo $content; ?></p>
</main>

See Also

Revisions

Top Editors
Recently Edited Articles