<commit_before><?php

namespace Phile\Template;

use Phile\Registry;
use Phile\Event;

class Twig implements TemplateInterface {
	/**
	 * @var array the complete phile config
	 */
	protected $settings;

	/**
	 * @var array the config for twig
	 */
	protected $config;

	/**
	 * @var \Phile\Model\Page
	 */
	protected $page;

	public function __construct($config = null)	{
		if (!is_null($config)) {
			$this->config = $config;
		}
		$this->settings = Registry::get('Phile_Settings');
	}

	public function setCurrentPage(\Phile\Model\Page $page) {
		$this->page = $page;
	}

	public function render() {
		$pageRepository = new \Phile\Repository\Page();
		$output = 'No template found!';
		if (file_exists(THEMES_DIR . $this->settings['theme'])) {
			$loader = new \Twig_Loader_Filesystem(THEMES_DIR . $this->settings['theme']);
			$twig = new \Twig_Environment($loader, $this->config);
			// load the twig debug extension if required
			if ($this->config['debug']) {
				$twig->addExtension(new \Twig_Extension_Debug());
			}
			$twig_vars = array(
				'config' => $this->settings,
				'base_dir' => rtrim(ROOT_DIR, '/'),
				'base_url' => $this->settings['base_url'],
				'theme_dir' => THEMES_DIR . $this->settings['theme'],
				'theme_url' => $this->settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $this->settings['theme'],
				'site_title' => $this->settings['site_title'],
				'current_page' => $this->page,
				'meta' => $this->page->getMeta(),
				'content' => $this->page->getContent(),
				'pages' => $pageRepository->findAll($this->settings),
			);

			if (Registry::isRegistered('templateVars')) {
				if (is_array(Registry::get('templateVars'))) {
					foreach (Registry::get('templateVars') as $key => $value) {
						$twig_vars[$key] = $value;
					}
				}
			}
			Event::triggerEvent('template_engine_registered', array('engine' => &$twig, 'data' => &$twig_vars));

			if ($this->page->getMeta()->get('template') !== null && file_exists(THEMES_DIR . $this->page->getMeta()->get('template').'.html')) {
				$template = $this->page->getMeta()->get('template');
			} else {
				$template = 'index';
			}

			$output = $twig->render($template .'.html', $twig_vars);
		}
		return $output;
	}
}<commit_msg>check selected themes dir for template<commit_after><?php

namespace Phile\Template;

use Phile\Registry;
use Phile\Event;

class Twig implements TemplateInterface {
	/**
	 * @var array the complete phile config
	 */
	protected $settings;

	/**
	 * @var array the config for twig
	 */
	protected $config;

	/**
	 * @var \Phile\Model\Page
	 */
	protected $page;

	public function __construct($config = null)	{
		if (!is_null($config)) {
			$this->config = $config;
		}
		$this->settings = Registry::get('Phile_Settings');
	}

	public function setCurrentPage(\Phile\Model\Page $page) {
		$this->page = $page;
	}

	public function render() {
		$pageRepository = new \Phile\Repository\Page();
		$output = 'No template found!';
		if (file_exists(THEMES_DIR . $this->settings['theme'])) {
			$loader = new \Twig_Loader_Filesystem(THEMES_DIR . $this->settings['theme']);
			$twig = new \Twig_Environment($loader, $this->config);
			// load the twig debug extension if required
			if ($this->config['debug']) {
				$twig->addExtension(new \Twig_Extension_Debug());
			}
			$twig_vars = array(
				'config' => $this->settings,
				'base_dir' => rtrim(ROOT_DIR, '/'),
				'base_url' => $this->settings['base_url'],
				'theme_dir' => THEMES_DIR . $this->settings['theme'],
				'theme_url' => $this->settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $this->settings['theme'],
				'site_title' => $this->settings['site_title'],
				'current_page' => $this->page,
				'meta' => $this->page->getMeta(),
				'content' => $this->page->getContent(),
				'pages' => $pageRepository->findAll($this->settings),
			);

			if (Registry::isRegistered('templateVars')) {
				if (is_array(Registry::get('templateVars'))) {
					foreach (Registry::get('templateVars') as $key => $value) {
						$twig_vars[$key] = $value;
					}
				}
			}
			Event::triggerEvent('template_engine_registered', array('engine' => &$twig, 'data' => &$twig_vars));
			
			$file = $twig_vars['theme_dir']. '/' . $this->page->getMeta()->get('template').'.html';
			if ($this->page->getMeta()->get('template') !== null && file_exists($file)) {
				$template = $this->page->getMeta()->get('template');
			} else {
				$template = 'index';
			}

			$output = $twig->render($template .'.html', $twig_vars);
		}
		return $output;
	}
}
{'fraction_non_alphanumeric': 0.2035968028419183, 'fraction_numerical': 0.0, 'mean_word_length': 3.928884026258206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3682982', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1527, 'n_words': 279}