Core

The WordPress Loop

The WordPress Loop is how WordPress gives a template the current page or post. TemplateX keeps that loop in the background so your template can start with the markup.

The Usual WordPress Shape#

In a normal WordPress template, even a small page starts with Loop code:

phpfront-page.php
<?php if ( have_posts() ) : ?>  <?php while ( have_posts() ) : the_post(); ?>    <main>      <h1><?php the_title(); ?></h1>      <?php the_content(); ?>    </main>  <?php endwhile; ?><?php endif; ?>

The Loop is powerful, but it can get between you and the page you are trying to write.

The TemplateX Shape#

In TemplateX, the same page can stay close to HTML:

phpresources/views/front-page.php
<main>  <h1>{{ title }}</h1>  {{ content }}</main>

TemplateX still compiles to native WordPress PHP. It just lets the source template focus on what the page should render.

Current Page Values#

On a normal template, values like {{ title }} and {{ content }} come from the current WordPress page or post.

Inside a query loop, the current item changes to each post in that query. That is why the same {{ title }} tag can mean the page title in one place and a post title inside a loop.

Native Values#

These values are available from the current WordPress page or post:

ValuePrints
{{ id }}The current post or page ID.
{{ title }}The current title.
{{ slug }}The current slug.
{{ excerpt }}The current excerpt.
{{ content }}The current content. As a bare value, it renders like normal WordPress content.
{{ url }}The current permalink URL.
{{ permalink }}The current permalink URL.
{{ featured_image }}The current featured image URL.
{{ featured }}The current featured image URL.
{{ date }}The current published date.
{{ author }}The current author display name.
{{ collection }}The current post type, such as post, page, or a custom post type.

These names are native WordPress values. If a custom field uses the same name, the native value wins.

Global Values#

These values are also available in templates, but they are about the current visitor or auth screen instead of the current post:

ValuePrints
{{ logged_in }}Whether the current visitor is logged in.
{{ registration_open }}Whether WordPress user registration is enabled.
{{ auth_action }}The current auth action.
{{ auth_login_url }}The login URL.
{{ auth_lost_password_url }}The lost password URL.
{{ auth_register_url }}The register URL.
{{ auth_logout_url }}The logout URL.