Views & Templates

PHPFast makes it easy to create dynamic web pages with its flexible view system. All views are stored in the application/Views/ folder, where you can use layouts, reusable components, and pass data to structure your templates efficiently.

Views Structure

ROOT
├── application/                       # Application-specific files
│   └── Views/                         # Views for frontend and backend
│       ├── Backend/                   # Backend views
│       ├── Frontend/                  # Frontend views (assets, components)
│       │   ├── Assets/                # Frontend assets (CSS, JS)
│       │   │   ├── css/               # CSS files
│       │   │   └── js/                # JS files
│       │   ├── Component/             # Reusable components (e.g., menu, search)
│       │   │   ├── header.php         # Header component
│       │   │   ├── footer.php         # Footer component
│       │   │   └── sidebar_main.php   # Sidebar main component
│       │   └── home_index.php         # Homepage view
│       ├── backend.php                # Backend layout
│       ├── frontend.php               # Frontend layout
│       ├── dashboard.php              # Dashboard layout
│       └── 404.php                    # Error layout

Creating a View

  1. Go to the application/View/ directory inside your PHPFast project.

  2. Inside your preferred folder, create a new PHP file (e.g., frontend/home_index.php).

  3. Open the file and insert your HTML and PHP code to structure the page.

Using manual way

A layout is a reusable template (e.g., header, footer) that wraps around the main content of your pages. You can store layouts in the View/ directory for better organization and reuse.

Example frontend.php layout:

Setup Controller

index() return $data to view Frontend/Home/index.php and in layout frontend.php will include this view.

Get data in view

Example in Frontend/Home/index.php:

Using Blocks

The PHPFast Framework organizes complex website interfaces by breaking them into independent blocks like head, header, content, and footer. This makes components easier to manage, reuse, and maintain, while also keeping interface and logic separate for better scalability.

That's why the PHPFast Framework implements a Block structure, making interface management more logical, structured, and efficient.

Find out how to use Blocks

When to use Manual or Blocks?

Depending on the first parameter of the render() method. If this layout uses Blocks, it will follow the second way.

Example:

Use the same HomeController above, but the layout display different.

Manual

If the code in layout frontend.php like this:

Blocks

If the code in layout frontend.php like this:

Error Pages

You can create custom error pages and store them in the application/Views/ directory. For example, to handle 404 errors, create a file named 404.php in that folder.

Last updated

Was this helpful?