PodsView::get_template_part PHP Method

get_template_part() public static method

public static get_template_part ( $_view, null | array $_data = null ) : boolean | mixed | string | void
$_view
$_data null | array
return boolean | mixed | string | void
    public static function get_template_part($_view, $_data = null)
    {
        /* to be reviewed later, should have more checks and restrictions like a whitelist etc
        		if ( 0 === strpos( $_view, 'http://' ) || 0 === strpos( $_view, 'https://' ) ) {
        			$_view = apply_filters( 'pods_view_url_include', $_view );
        
        			if ( empty( $_view ) || ( defined( 'PODS_REMOTE_VIEWS' ) && PODS_REMOTE_VIEWS ) )
        				return '';
        
        			$response = wp_remote_get( $_view );
        
        			return wp_remote_retrieve_body( $response );
        		}*/
        $_view = self::locate_template($_view);
        if (empty($_view)) {
            return $_view;
        }
        if (!empty($_data) && is_array($_data)) {
            extract($_data, EXTR_SKIP);
        }
        ob_start();
        require $_view;
        $output = ob_get_clean();
        return $output;
    }

Usage Example

Ejemplo n.º 1
0
/**
 * Scope variables and include a template like get_template_part that's child-theme aware
 *
 * @see get_template_part
 *
 * @param string|array $template Template names (see get_template_part)
 * @param array $data Data to scope to the include
 * @param bool $return Whether to return the output (echo by default)
 * @return string|null Template output
 *
 * @since 2.3.9
 */
function pods_template_part($template, $data = null, $return = false)
{
    $part = PodsView::get_template_part($template, $data);
    if (!$return) {
        echo $part;
        return null;
    }
    return $part;
}