# easy-invoice/2.3.7/includes/Traits/TemplateTrait.php

Easy Invoice – Invoice Generator, PDF Quotes &amp; Payments, version 2.3.7. 61 lines.

- Page: https://pluginprobe.com/plugins/easy-invoice/2.3.7/code/includes/Traits/TemplateTrait.php
- Raw: https://pluginprobe.com/plugins/easy-invoice/2.3.7/raw/includes/Traits/TemplateTrait.php
- Modified: 2025-08-14T09:51:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/easy-invoice/2.3.7/code/includes/Traits/TemplateTrait.php#L10-L20`.

```php
<?php
/**
 * Template Trait
 *
 * @package Easy_Invoice
 * @subpackage Traits
 */

namespace EasyInvoice\Traits;

use EasyInvoice\Controllers\SettingsController;

/**
 * TemplateTrait contains methods for template handling
 */
trait TemplateTrait {
    /**
     * Get common template variables
     * 
     * @return array Common template variables
     */
    protected function getCommonTemplateVars() {
        $settings_controller = new SettingsController();
        $settings = $settings_controller->getSettings();
        
        // Ensure settings is an array and has default values
        if (!is_array($settings)) {
            $settings = [];
        }
        
        return [
            'company' => $settings['company'] ?? '',
            'currency_symbol' => isset($settings['currency']['symbol']) ? $settings['currency']['symbol'] : '$',
            'currency_position' => isset($settings['currency']['position']) ? $settings['currency']['position'] : 'left',
        ];
    }
    
    /**
     * Display a template with given variables
     *
     * @param string $template_path Path to the template file
     * @param array $vars Variables to extract for the template
     * @return void
     */
    protected function displayTemplate($template_path, $vars = []) {
        // Add common template variables if not already provided
        if (!isset($vars['template_vars'])) {
            $vars['template_vars'] = $this->getCommonTemplateVars();
        }

        // Extract variables for use in the template
        extract($vars);
        
        // Include the template file
        if (file_exists($template_path)) {
            include $template_path;
        } else {
            wp_die(sprintf(__('Template file not found: %s', 'easy-invoice'), $template_path));
        }
    }
} 
```
