Partial was created to speed up theme creation and organization by letting developers quickly breakup and reuse small self contained parts of their theme templates.

It favours a set of simple conventions over defining and configuring a set of specific theme functions and implementing theme hooks.

Drupal 8/9

Usage:

Partial returns a rendered version of the template that you can just output.

Here is a simple use case using a #markup element in a render array.

    $content['sections']['archives'] = [
      '#markup' => partial('documentation_section'),
    ];

Here is a nested partials example showing how to also pass variables around to a partial template.

    $content['sections']['archives'] = [
      '#markup' => partial('documentation_section', [
        'id' => 'archives',
        'title' => $this->t('How to create an archive'),
        'content' => partial('documentation_archive'),
      ]),
    ];

Partial defines a theme suggestion using the pattern “partial__{$partial_name}”. (Remember that Drupal defines suggestions using underscores, but filenames use dashes, see further bellow)

We suggest that, by convention, partial templates be located in your themes templates/partials sub-folder. So in the above example you would be creating two template files respectively called partial--documention-section and partial--documention-archive.

Twig Extension - Function & Filter

The module also provides Twig extensions

Usage:

Examples needed

Drupal 7

Usage:

Partial returns a rendered version of the template that you can just output.

Here is a simple use case where

    $content['sections']['archives'] = [
      '#markup' => partial('documentation_section'),
    ];

Partial defines a theme suggestion using the pattern “partial__{$partial_name}”.

We suggest that, by convention, partial templates be located in your themes templates/partials sub-folder.

- you can use it directly in a .tpl.php file using the following pattern:

<div class=“page-header”>
  <?php print partial(‘header’, array(‘title’ => $page[‘title’])); ?>
</div>

which will resolves to [path to your theme]/templates/partials/partial—header.tpl.php and make the $title variable available from printing in the theme.

- you can use it in a renderable array using this pattern:

$elements = array(‘title’ => $page[‘title’]);
$build = array(
  ‘header’ => array(
    ‘#markup’ => partial(‘header’, $elements),
  ),
);

and then

<?php print render($build); ?>

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • chart icon34 sites report using this module
  • Created by notauseranymore on , updated
  • shieldStable releases for this project are covered by the security advisory policy.
    There are currently no supported stable releases.

Releases