Skip to content
Learn Netverks

Lesson

Step 27/36 75% through track

includes-templates

Includes and simple templates

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Includes and simple templates: the syntax, APIs, and habits you need before advancing in PHP.

Teams ship Includes and simple templates on every PHP codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Includes and simple templates in contexts like: LAMP/LEMP stacks, Laravel apps, WordPress themes/plugins, and shared hosting.

Write PHP in the editor and click Run on server—the dev runner executes your script and returns stdout/stderr (set LEARNING_RUNNER_ENABLED=true locally).

When you can explain the previous lesson's ideas without copying starter code.

Split pages into reusable pieces with include, require, and template partials. Frameworks (Blade, Twig) add escaping and layout inheritance—understand plain includes first.

include vs require

  • require — fatal error if missing (critical files)
  • include — warning if missing (optional partials)
  • require_once / include_once — skip if already loaded

Simple layout pattern

// header.php
<!DOCTYPE html><html><head><title><?= $title ?></title></head><body>
// page.php
$title = 'Products';
require 'header.php';
echo '<main>...</main>';
require 'footer.php';

Escaping in templates

Always escape dynamic HTML: <?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>. Never mix SQL into templates—that belongs in data layer with prepared statements.

Self-check

  1. When choose require over include?
  2. Why separate layout partials?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • require vs include?
  • Path traversal risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump