<?php
/**
 * Necessary methods for template.
 *
 * @since 1.0.9
 *
 * @package SplendorStudio\Framework\API
*/
trait Template_Trait {
	/**
	 * Render a template
	 *
	 * @since    1.0.9
	 */
	protected static function render_template( $default_template_path = false, $variables = array(), $require = 'once' ){
		if ( ! $template_path = locate_template( basename( $default_template_path ) ) ) {
			$template_path =  FANCIFY_TEMPLATES_PATH . $default_template_path;
		}

		if ( is_file( $template_path ) ) {
			extract( $variables );
			ob_start();
			if ( 'always' == $require ) {
				require( $template_path );// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound -- valid usecase
			} else {
				require_once( $template_path );// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound -- valid usecase
			}
			$template_content = apply_filters( 'fancify_lite_template_content', ob_get_clean(), $default_template_path, $template_path, $variables );
		} else {
			$template_content = '';
		}

		return $template_content;
	}
}