Create a Page

Pages are the essence of MachCMS. The entire system is page based. Pages are actually really simple, but may not be so simple without a little docs to help you along.

Step 1

Time to build the main frame.

Open the pages folder. Inside you should find some default pages that come like that with MachCMS. You will notice they all have a .page suffix. Why is this? It's just an identifier, to show you that it's a page. In the future if we add a desktop GUI page editor. This will help the recognition of pages.

So in the pages folder you need to create a new folder named
If you like, you can change New_Page to anything you wish.

Inside this new *.page folder create a new file named main.php.
MachCMS is a PHP system. You don't need to know PHP in order to build pages, but it will help you.

So what does main.php contain, and what does it do? We'll answer that in step 2.

Step 2

The main purpose of the main.php file is to define what the template contains. It is included into the Template class. So how to do it?

Let's say for example that you want to define Page_Title in the template. You would use the following line in main.php:
$template->Page_Title = "This is my page title";

Or if you want to define Page_Content:
$template->Page_Content = "This is my page content!";

Doing this replaces <!--Page_Content--> in the template with "This is my page content!".

main.php can contain any valid PHP except for functions and classes. If you need that functionality, do it at a system level.


Go to it in your browser like this: http://domain.tld/machcms/MyPage
Or ...machcms/?q=MyPage if you are using the url linkType.

Available Functions

There are a few PHP functions that can be very useful for building pages.


The functions start_buffer() and end_buffer() use output control to buffer the output and return it later with end_buffer(). How to use it?

echo 'This is something here';
// ... do a bunch of stuff
echo 'some more stuff';
$template->Page_Content = end_buffer();

What does it do. start_buffer(); starts the output control.
Now you can use echo, print, etc. function to output stuff.
And when you have everything you want, you can end it and give the content over to a template directive such as Page_Content like this:
$template->Page_Content = end_buffer();

There are two simple yet very useful functions you can use on your pages.


This function creates a link to a MachCMS page. $pageName is the name of the page. Here's an example on how to use it.

echo '<a href="' . make_link("MyPage") . '">Link to MyPage</a>';

This function behaves the same way as the LINK:* template directive.
Previous (Configuration) Table of Contents Next (Building a Template) Logo