PHPackages                             freshflesh/wp-render-template-part - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. freshflesh/wp-render-template-part

ActiveLibrary[Templating &amp; Views](/categories/templating)

freshflesh/wp-render-template-part
==================================

An alternative to the native WP function `get\_template\_part` that can pass arguments to the local scope

1.1.2(9y ago)52.9k2[1 PRs](https://github.com/FreshFlesh/wp-render-template-part/pulls)MITPHPPHP &gt;=5.2.0

Since Aug 3Pushed 9y ago4 watchersCompare

[ Source](https://github.com/FreshFlesh/wp-render-template-part)[ Packagist](https://packagist.org/packages/freshflesh/wp-render-template-part)[ Docs](https://github.com/thomascharbit/wp-render-template-part)[ RSS](/packages/freshflesh-wp-render-template-part/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

render\_template\_part()
========================

[](#render_template_part)

An alternative to the native WordPress function `get_template_part()` that can pass arguments to the local scope.

Installation
------------

[](#installation)

- Using composer : `composer require freshflesh/wp-render-template-part`
- Or manually download and include the `src/wp-render-template-part.php` file

\##Parameters

- **$slug**: (string) (Required) The slug name for the generic template.
- **$name**: (string) (Optional) The name of the specialised template. Default value: null
- **$args**: (array) (Optional) An associative array containing arguments to pass to the template. Default empty array.
- **$echo**: (boolean) (Optional) Wether to echo or return the rendered template. Default is true.

Usage
-----

[](#usage)

To pass arguments to a template partial, use the `render_template_part()` function.

#### Simple example

[](#simple-example)

Parent template:

```

```

#### Returning value example

[](#returning-value-example)

Useful when returning templates through AJAX for instance:

```
