User Tools

Site Tools


how_to_create_a_page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
how_to_create_a_page [2020/08/17 12:21]
A User Not Logged in old revision restored (2020/08/16 15:49)
how_to_create_a_page [2020/08/27 11:58] (current)
A User Not Logged in old revision restored (2018/12/03 13:44)
Line 1: Line 1:
 ====== How To Create A New 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.+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.
  
-<file php pages/mypage.php>+<file php pages/mypage.inc.php>
 <?php <?php
   document::$snippets['title'][] = 'Your head title here';   document::$snippets['title'][] = 'Your head title here';
   document::$snippets['description'] = 'Your meta description here';   document::$snippets['description'] = 'Your meta description here';
-   +?> 
-  echo 'Hello World'; +<h1>Hello World</h1> 
- ?>+<p>Lorem ipsum dolor...</p>
 </file> </file>
  
-Mostly we want a page to look different in every template. That's when we need to separate HTML from PHP logic. This is where a LiteCart View Object will become handySimply fill it with data and stitch it with a view.+The page is then accessed by http://www.yourdomain.com/mypage
  
-<file php pages/mypage.php>+===== 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. 
 + 
 +<file php pages/mypage.inc.php>
 <?php <?php
   document::$snippets['title'][] = 'Your head title here';   document::$snippets['title'][] = 'Your head title here';
Line 26: Line 30:
   );   );
      
-  echo $_mypage->stitch('views/mypage');+  echo $_mypage->stitch('pages/mypage');
 ?> ?>
 </file> </file>
Line 32: Line 36:
 Here is an example of a template view file: Here is an example of a template view file:
  
-<file php includes/templates/views/mypage.inc.php> +<file php includes/templates/mytemplate.catalog/pages/mypage.inc.php> 
-<section+<main id="content"
-  <h1>{snippet:title}</h1> +  <h1><?php echo $title; ?></h1> 
-  <div class="content">{snippet:content}</div+  <p><?php echo $content; ?></p
-</section>+</main>
 </file> </file>
  
 Any snippet can be retrieved by one of the following, depending on when most suitable: 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 +  * <?php echo $parameter; ?> 
-  * <!--snippet:parameter-->     <-- The element way if stated as placeholder +  * {snippet:parameter
-  * {snippet:parameter}          <-- The parameter way if stated in javascript or attributes+ 
 +If passive snippet is not defined it can be inserted by a later defined global variable. Otherwise cleaned up before sent back to the browser.
how_to_create_a_page.txt · Last modified: 2020/08/27 11:58 by A User Not Logged in