开发者

Fastest PHP template engine (or framework) supporting inheritance for multiple sites

开发者 https://www.devze.com 2023-03-06 12:45 出处:网络
I need to find a template engine and/or a framework in PHP that lets me publish a website with one template, and reuse the template on other websites on the same server by making a child template, whe

I need to find a template engine and/or a framework in PHP that lets me publish a website with one template, and reuse the template on other websites on the same server by making a child template, where I only override certain design elements from the parent template.

What I am looking for is speed of deployment - which template engine (PHP required) can I use to get the additional sites out there, the fastest?

As an example, I have websites to launch for various markets, in different categories. So I would create a UK site template that is the master template, then override details like the logo and stati开发者_Python百科c texts for the Swedish and French markets. Additionally, for different categories (such as Men's Fashion vs. Women's Fashion) I would need to override the images and colors of certain design elements (like pictures on the front page, and so on).

All of the sites I need to launch are based on the same API (RESTful JSON), and I need to be able to easily integrate a form for searching, sorting and filtering - so the template engine would have to allow for easy integration with variables...

Which solution would you suggest fit these requirements?


You could also look at Twig. Here is some more info on it and how it compares to the others: http://fabien.potencier.org/article/34/templating-engines-in-php


Simple -> Symfony

Uses a very simple templating engine - and easy to learn as their documentation is so amazing


Hrm. Set up codeigniter 2 with packages and the template library 'extension', put the template files in a separate repository and load them up as a package for each 'child site'. If you define your regions carefully that should be all you need to do :)


If not a framework but a template engine I can't think of anything else than using Smarty for templating. It's easy to use and very flexible. You can create a main template e.g. main.tpl put in some variables and re-use that template over and over by just assigning needed values for each site e.g. index.php (for some site):

$smarty->assign(array(
   'PageTitle' => 'Some site title'
   'CustomContent' => $smarty->fetch('custom.tpl'); // custom for this site
));

// of course you've setup the template location at this point
$MainTemplate = $smarty->fetch('main.tpl');

$smarty->display($MainTemplate);

On main.tpl you'd have something like:

// on main.tpl you'd have
<title>{$PageTitle}</title>
......
<body>
{$CustomContent}
</body>

Just an idea :)


Zend Framework and setting up different 'sites' as modules would probably be a good approach if they share a lot of logic etc. Each module could have a unique layout.

Zend Framework allows you to work using the MVC pattern and makes it easy to separate logic and presentation. You can find more information at http://framework.zend.com/


I suggest http://agiletoolkit.org/ for the following reasons:

  • built-in and integrated component-level templates. CSS framework is based on jQuery UI CSS and 960.gs. Most frameworks handle templates on page-level, which makes them less re-usable.
  • out-of-the-box forms with ajax support, filters in different shapes and html/css layouts. UI components work with MVC or static array data (which is easy to use with JSON). Most framework do not supply form HTML. Also generators typically would integrate ui elements with models only.
  • object-oriented component approach constructs site from "views objects" which you can share between multiple sites and merge with different models. Pages are also defined as classes. That means you can have 2 pages with common ancestor and minor changes. If you know OOP it becomes a powerful feature. Most frameworks would require separate installation and sharing components is more difficult. Also most frameworks would require a separate template per page.
  • solution is much more lightweight, geared towards efficient development and integration. In comparison, zend focuses on component independence. Light footprint, and faster speed is direct result of this.

Agile Toolkit is open source.

I hope this information could bring some fresh insight and see development from different perspective. I actively work with the framework, documentation is in-complete at this time and under construction, but the architecture is very promising and requires to know only some PHP and object-oriented programming skills.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号