This repository has been archived by the owner on Mar 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eb611c
commit 8c5a79c
Showing
125 changed files
with
25,712 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
phileTemplateSmarty | ||
=================== | ||
|
||
Smarty template parser for PhileCMS | ||
[Smarty](http://www.smarty.net/docs/en/)(version 3.1.15 included) template parser for [PhileCMS](https://github.com/PhileCMS/Phile) | ||
|
||
### Installation | ||
|
||
[Download this file](https://github.com/PhileCMS/phileTemplateSmarty/archive/master.zip "Download ZIP File") and drop it into the root Phile installation directory. | ||
|
||
Modify your `config.php` file: | ||
|
||
```php | ||
$config['plugins'] = array( | ||
// disable the Twig template engine | ||
'phileTemplateTwig' => array('active' => false), | ||
// enable the Smarty template engine | ||
'phileTemplateSmarty' => array('active' => true) | ||
); | ||
``` | ||
|
||
### Disclaimer | ||
|
||
Due to the nature of the Page model in Phile, and the fact that Smarty doesn't like objects, there are some slightly different properties available to the `pages` array. | ||
|
||
* title | ||
* url | ||
* content | ||
* meta | ||
|
||
This covers most of the things that the `pages` array covers in Twig. | ||
|
||
### Not a drop in replacement for Twig | ||
|
||
If you have not used Smarty before, please read the [docs](http://www.smarty.net/docs/en/) because there are a few differences in syntax, and philosophy, over Twig. | ||
|
||
I have included an index.tpl file to show how to recreate the index page from the default theme. | ||
|
||
### Why use this over Twig | ||
|
||
* You prefer Smarty syntax/style/philosophy | ||
* Smarty has a large community than Twig (Smarty is older) | ||
* Some argue Smarty is faster than Twig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" class="no-js"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<base href="{$base_url}/" /> | ||
<title>{$meta.title} | {$site_title}</title> | ||
<meta property="og:type" content="article" /> | ||
<meta property="og:title" content="{$current_page.title} | {$site_title}" /> | ||
<meta property="og:description" content="{$meta.description}" /> | ||
<meta property="og:url" content="{$current_page.url}" /> | ||
<meta property="og:site_name" content="{$site_title}" /> | ||
<link rel="stylesheet" href="{$theme_url}/css/style.css" type="text/css" /> | ||
<link rel="stylesheet" href="{$theme_url}/css/tomorrow-night.css" type="text/css" /> | ||
</head> | ||
<body> | ||
<header id="header"> | ||
<div class="inner clearfix"> | ||
<h1><a href="{$base_url}">{$site_title}</a></h1> | ||
<ul class="nav"> | ||
{foreach $pages as $page} | ||
<li><a href="{$page.url}">{$page.title}</a></li> | ||
{/foreach} | ||
</ul> | ||
</div> | ||
</header> | ||
<section id="content"> | ||
<div class="inner"> | ||
{$content} | ||
</div> | ||
</section> | ||
<footer id="footer"> | ||
<div class="inner"> | ||
<a href="https://github.com/PhileCMS/Phile">Phile</a> was made by <a href="https://github.com/PhileCMS">The PhileCMS Community</a>. | ||
</div> | ||
</footer> | ||
<script src="{$theme_url}/js/highlight.js"></script> | ||
<script>hljs.initHighlightingOnLoad();</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Phile\Template; | ||
|
||
use Phile\Registry; | ||
use Phile\Event; | ||
|
||
class Smarty implements TemplateInterface { | ||
/** | ||
* @var array the complete phile config | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @var array the config for smarty | ||
*/ | ||
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'])) { | ||
require_once('smarty-lib/Smarty.class.php'); | ||
$smarty = new \Smarty(); | ||
$smarty->setTemplateDir(THEMES_DIR . $this->settings['theme']); | ||
$smarty->setCompileDir(THEMES_DIR . $this->settings['theme'] . '/_compiled'); | ||
$smarty->setCacheDir($this->config['cache_dir']); | ||
$smarty->debugging = $this->config['debugging']; | ||
$data = 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' => array( | ||
'title' => $this->page->getTitle(), | ||
'url' => $this->page->getUrl() | ||
), | ||
'meta' => $this->page->getMeta(), | ||
'content' => $this->page->getContent() | ||
); | ||
// we need to break down this object for Smarty | ||
$pages = $pageRepository->findAll($this->settings); | ||
$data['pages'] = array(); | ||
for ($i=0; $i < count($pages); $i++) { | ||
$data['pages'][] = array( | ||
'title' => $pages[$i]->getTitle(), | ||
'url' => $pages[$i]->getUrl(), | ||
'content' => $pages[$i]->getContent(), | ||
'meta' => $pages[$i]->getMeta() | ||
); | ||
} | ||
// assign the data | ||
foreach ($data as $key => $value) { | ||
$smarty->assign($key, $value); | ||
} | ||
|
||
Event::triggerEvent('template_engine_registered', array('engine' => &$smarty)); | ||
|
||
$template = ($this->page->getMeta()->get('template') !== null) ? $this->page->getMeta()->get('template') : 'index'; | ||
$smarty->display($template . '.tpl'); | ||
} | ||
return $output; | ||
} | ||
} |
Oops, something went wrong.