index.php
In Prisma PHP, routing is derived from your file system. An index.php file acts as the UI entry point for a specific route segment.
Creating a Page
To create the home page of your application, simply edit the index.php file at the root of your app directory.
<?php
use PP\MainLayout;
MainLayout::$title = 'Home';
MainLayout::$description = 'The first page of the application.';
?>
<div>
<h1>Hello, World!</h1>
</div>
http://localhost:3000/
Nested Routes
To create complex URL paths, you simply nest folders. The folder name becomes the URL segment.
| Folder Structure | Resulting URL |
|---|---|
|
app/index.php
|
/ |
|
app/dashboard/index.php
|
/dashboard |
|
app/dashboard/settings/index.php
|
/dashboard/settings |
<?php
use PP\MainLayout;
MainLayout::$title = 'Settings';
?>
<div>
<h1>Settings Page</h1>
<p>This content lives at /dashboard/settings</p>
</div>
The shape of a route file
This is the rule that trips people up most often. PHP first, then exactly one parent HTML element
as the route boundary. Everything visible goes inside it, and when the page needs client logic, a single plain
<script> is the last child of that same root.
<?php
use PP\MainLayout;
MainLayout::$title = 'Todos';
MainLayout::$description = 'Track tasks and view the current item count.';
?>
<div>
<section>
<h1>Todos</h1>
<p>Count: {count}</p>
</section>
<script>
const [count, setCount] = pp.state(0);
</script>
</div>
Do
- Wrap semantic content such as
<main>or<section>in a neutral<div>root, so the script can stay inside the boundary without living in the content element. - Write PulsePoint state and functions at the top level of that script.
- Set metadata with
MainLayout::$titleandMainLayout::$description; a local$titlevariable only affects rendered text.
Do not
- Write
pp-componentyourself — Prisma PHP injects it on the route root at compile time. - Put any
typeattribute on the component script; the runtime only recognises a script with none. - Leave the
<script>outside the route root, or wrap its contents inDOMContentLoaded, an IIFE, or a manualpp.mount().
The same one-root rule applies to nested layout.php files and to partials rendered with ImportComponent. For the client-side half, see PulsePoint.
View vs Logic
Remember: index.php is for rendering UI (HTML). If you need to return JSON data (like an API) or handle form processing without a view, use route.php instead.