User Tools

Site Tools


how_to_create_a_page

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 the web server 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 http://www.yourdomain.com/mypage

How To Separate HTML from PHP - Use A Template View

Mostly a page looks different in each and every template. That's when we need to separate the HTML from the PHP logic. This is where a LiteCart View Object will become handy. Simply fill it with data and stitch it with a view.

pages/mypage.inc.php
<?php
  document::$snippets['title'][] = 'Your head title here';
  document::$snippets['description'] = 'Your meta description here';
 
  $_mypage = new view();
 
  $_mypage->snippets = array(
    'title' => 'Hello World',
    'content' => 'Lorem ipsum dolor',
  );
 
  echo $_mypage->stitch('pages/mypage');
?>

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>

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

  • <?php echo $parameter; ?> ←- The PHP way if u need to process the data inside the view
  • <!–snippet:parameter–> ←- The element way if stated as an invisible placeholder
  • {snippet:parameter} ←- The parameter way if stated in javascript or attributes
how_to_create_a_page.txt · Last modified: 2017/03/21 14:49 by admin