Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Partial

Security covered Maintenance fixes only 25 sites

Part of the Partial ecosystem · 5 projects

This module helps theme developers create and organize reusable template components. It allows you to easily include small, self-contained parts of your theme within other templates, simplifying the development process.

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); ?>

Ask your assistant about Partial

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Oct 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
2.0.x-dev Dev 9–10 Oct 25, 2023