Simple Website Engine

Simple Yet Powerful Website Generator

Simple Website Engine Documentation

Welcome to the Simple Website Engine (SWSE) documentation. This documentation provides an overview of the core concepts, features, and usage of SWSE.

SWSE is a lightweight PHP framework designed to simplify the process of building dynamic websites and web applications.

 

With SWSE web pages could look like this:

https://server.com/

<!DOCTYPE html>
<html lang="en">
<head>
<!--include:/sections/head.html ["title" => "Home Page"]-->
</head>
<body>
<!--include:/sections/navigation.html-->
<section>
    <h1>Welcome to SWSE, <!--$user-->!</h1>
    <p>This is a simple web page powered by SWSE.</p>
</section>
<!--include:/sections/footer.html-->
</body>
</html>

https://server.com/about

<!DOCTYPE html>
<html lang="en">
<head>
<!--include:/sections/head.html ["title" => "About us"]-->
</head>
<body>
<!--include:/sections/navigation.html-->
<section>
    <h1>About us!</h1>
    <p>This is a simple web page powered by SWSE.</p>
</section>
<!--include:/sections/footer.html-->
</body>
</html>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><!--$title--></title>
<link rel="stylesheet" href="/assets/css/style.css" />
<nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
    <!--if ($isLogged)-->
        <a href="/profile">Profile</a>
        <a href="/logout">Logout</a>
    <!--endif-->
    <!--if (!$isLogged)-->
        <a href="/login">Login</a>
    <!--endif-->
</nav>
<footer>
<p>&copy; <!--date Y--> My Website</p>
</footer>

Or if layout approach is used:

<!DOCTYPE html>
<html lang="en">
<head>
    <!--include:/sections/head.html-->
</head>
<body>
    <!--include:/sections/navigation.html-->
    <section>
        <!--layout-content-->
    </section>
    <!--include:/sections/footer.html-->
</body>
</html>

https://server.com/

<!--layout:/default.html ["title" => "Home Page"]-->

<h1>Welcome to SWSE, <!--$user-->!</h1>
<p>This is a simple web page powered by SWSE.</p>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><!--$title--></title>
<link rel="stylesheet" href="/assets/css/style.css" />
<nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
    <!--if ($isLogged)-->
        <a href="/profile">Profile</a>
        <a href="/logout">Logout</a>
    <!--endif-->
    <!--if (!$isLogged)-->
        <a href="/login">Login</a>
    <!--endif-->
</nav>
<footer>
<p>&copy; <!--date Y--> My Website</p>
</footer>

This is not a full-blown framework to build a massive application, use it for small to medium projects or prototypes.

Getting Started

1. Creating the project structure

Create the following structure in the project folder, for example /var/www/project-root

/var/www/project-root/
│-- actions/                    # PHP action handlers
│-- views/                      # HTML templates and views
│-- public/                     # Publicly accessible files (index.php, assets, etc.)

Please make sure that the document root is set to the /var/www/project-root/public directory. This would prevent unauthorized access to the application code and views.

2. Get the SWSE from GitHub

Then get the SWSE repository from GitHub

Place the repository into the /var/www/project-root/swse directory. The new structure would look like this:

/var/www/project-root/
│-- actions/                    # PHP action handlers
│-- views/                      # HTML templates and views
│-- public/                     # Publicly accessible files (index.php, assets, etc.)
│-- swse/                       # SWSE core engine files

3. Add Public files into the public directory

.htaccess file

Add the following file into /var/www/project-root/public/.htaccess

RewriteEngine On

# Don't rewrite files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route everything through index.php
RewriteRule ^(.*)$ index.php [QSA,L]

This would redirect any request through index.php in the public directory. See an example how to use url rewrites here.

index.php file

Add the following file into /var/www/project-root/public/index.php

<?php
include_once(__DIR__ . '/../swse/engine.php');
process(dirname(__DIR__));

This file initializes the SWSE engine and processes incoming requests. Adjust the path to the engine in case the structure is different.

4. (Optional) Add .env file into project root directory

Create a .env file into the project root directory

/var/www/project-root/
│-- actions/
│-- views/
│-- public/
│-- .env                        # Project configurations

Place configuration settings in the .env file. Such as database connection, stripe keys, turnstile secrets, etc. Example:

#.env file
APP_ID=app_id
PAGINATION=20

It's a good practice to use all caps for the parameter names.

The parameters can be accessed with $_ENV['APP_ID'] in the actions or <!--e('APP_ID')--> in the views.

File structure

Directories can be used in the actions and views folders to organize code.

For example, to have a /blog functionality which is separate from the main site structure, create a /blog directory in both actions and views folders.

Code in /blog directory:

/var/www/project-root/blog/
│-- index.php                        # Handle article list requests (with pagination)
│-- article.php                      # Handle single article requests

Urls for those actions:

https://example.com/blog/            # would map to /blog/index.php
https://example.com/blog/article     # would map to /blog/article.php

The same structure would be used in the views folder to organize the templates. For example:

/var/www/project-root/views/blog/
│-- index.html        # Template for article list
│-- article.html      # Template for single article

Note that index in each url cold be skipped as this would be the default file in the directory

Additional Configuration

Optinally make the project-root a GIT repository. If making it a repository, create a .gitignore file to exclude at least swse

# .gitignore file
swse

Next steps:

FAQ:

Why this is not a PHP Composer package

The SWSE is within only one file and it's not intended to build complex projects. For something robust - use Laravel, Symfony, or other full-featured frameworks. The SWSE is meant to be simple and easy to use without the need of Composer or other package managers.