Partials

Current Values

Partials render in the current context, so they can read the values available where they are called.

Post Cards#

Create a reusable post card:

phpresources/views/partials/post-card.php
<article>  <h2><a href="{{ url }}">{{ title }}</a></h2>  <p>{{ excerpt }}</p></article>

Use it inside a query loop:

phpresources/views/front-page.php
{{ query:posts }}  <PostCard />{{ /query:posts }}

Inside query:posts, values such as {{ title }}, {{ url }}, and {{ excerpt }} come from the current post.

Reuse The Same Partial#

The same partial can be used anywhere the same values exist:

phpresources/views/single.php
<PostCard />

TemplateX compiles the partial into native PHP with the current WordPress context.