Partials

Creating Partials

Create a partial when a piece of markup should live in one reusable file.

Location#

Partials live in resources/views/partials:

phpresources/views/partials/hello.php
<p>Hello world.</p>

Use the file name as a capitalized component tag:

phpresources/views/front-page.php
<Hello />

hello.php becomes <Hello />.

Naming#

Use clear, small names for partial files:

  • header.php becomes <Header />
  • footer.php becomes <Footer />
  • post-card.php becomes <PostCard />
  • language-switcher.php becomes <LanguageSwitcher />

Partial source files are still .php files, even when they are mostly HTML and TemplateX tags.