From 27f8c40c1215d2356cd02de4d9b195fc52fab5db Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Wed, 25 Jul 2018 17:22:10 +0200
Subject: [PATCH] Added Template trait.

---
 src/BuildDirector/LegacyBuildDirector.php |  2 +-
 src/Plugin/Template.php                   | 61 +++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 src/Plugin/Template.php

diff --git a/src/BuildDirector/LegacyBuildDirector.php b/src/BuildDirector/LegacyBuildDirector.php
index 90e0162..ba28304 100644
--- a/src/BuildDirector/LegacyBuildDirector.php
+++ b/src/BuildDirector/LegacyBuildDirector.php
@@ -27,7 +27,7 @@ class LegacyBuildDirector {
 	}
 
 	/**
-	 * Returns built plugin
+	 * Returns built pluginPluginAccess.php
 	 *
 	 * @return AbstractPlugin
 	 */
diff --git a/src/Plugin/Template.php b/src/Plugin/Template.php
new file mode 100644
index 0000000..9e1ca9b
--- /dev/null
+++ b/src/Plugin/Template.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace WPDesk\PluginBuilder\Plugin;
+
+trait Template {
+
+	/**
+	 * Plugin path.
+	 *
+	 * @var string
+	 */
+	public $plugin_path;
+
+	/**
+	 * Template path.
+	 *
+	 * @var string
+	 */
+	public $template_path;
+
+	/**
+	 * Init base variables for plugin
+	 */
+	public function init_template_base_variables() {
+		$this->plugin_path   = $this->plugin_info->get_plugin_dir();
+		$this->template_path = $this->plugin_info->get_text_domain();
+	}
+
+	/**
+	 * Renders end returns selected template
+	 *
+	 * @param string $name Name of the template.
+	 * @param string $path Additional inner path to the template.
+	 * @param array  $args args Accessible from template.
+	 *
+	 * @return string
+	 */
+	public function load_template( $name, $path = '', $args = array() ) {
+		$plugin_template_path = trailingslashit( $this->plugin_path ) . 'templates/';
+
+		// Look within passed path within the theme - this is priority.
+		$template = locate_template(
+			array(
+				trailingslashit( $this->get_template_path() ) . trailingslashit( $path ) . $name . '.php',
+			)
+		);
+
+		if ( ! $template ) {
+			$template = $plugin_template_path . trailingslashit( $path ) . $name . '.php';
+		}
+
+		extract( $args );
+		ob_start();
+		include( $template );
+
+		return ob_get_clean();
+	}
+
+
+
+}
\ No newline at end of file
-- 
GitLab