Display the page template
Contents
Function Definition
public function template ( $template, $code = null, $deprecated = false )
Source File: /pods/classes/Pods.php
Since: 2.0
Parameters
PARAMETER | TYPE | DETAILS |
---|---|---|
$template | (string) | The template name |
$code | (string) | Custom template code to use instead |
$deprecated | (bool) | Whether to use deprecated functionality based on old function usage |
Returns
(mixed) Template output
Examples
Display Items With A Template
This method does its own internal loop, therefore parsing Pods items with template() is very easy.
<?php echo pods( 'pod_name', array( 'limit' => 5 ) )->template( 'template_name' );
Using template() In A Loop
While using a while loop around template() is not necessary, it might be required. If that is the case, it is necessary to reset the id before calling template(). This causes its internal loop to only output one item and allows the main loop to function as expected.
<?php $params = array( 'limit' => -1 ); $pods = pods( 'pod_name', $params ); if ( $pods->total() > 0 ) { while( $pods->fetch() ) { //reset id $pods->id = $pods->id(); //get the template $temp = $pods->template( 'name of template' ); //output template if it exists if ( isset( $temp ) ) { echo $pods->display( 'some_other_field' ); echo $temp; } } //pagination echo $pods->pagination(); } else { echo 'No content found.'; }