views:

47

answers:

4

Hi,

How to create template/theme system and plugin system for a custom CMS similar to Wordpress or joomla?

Edit:

I don't want to use any templating engine similar to wordpress; a reason why it is famous for templating.

A: 

http://www.smarty.net/ ?

Māris Kiseļovs
I don't want to use any templating engine, see my edit please. Also this doesn't tell about plugin system. Thanks
Web Logic
A: 
$varArray = array('firstVar' => 'the value', 'secondVar' => 255);
$varArray['theThirdVar'] = 12345;
foreach($varArray as $name => $value){
    $$name = $value;
}
include ('templates/template.php');

in the template.php then do something like:

<?echo $firstVar;?>

this then should give you the Value

EDIT: This is a minimal example. You also could take a look into codeigniter source. They also use this kindo of Template System.

ITroubs
This. Best practice. But I'd use just extract() instead of the foreach. Also personally I've transitioned to a `include(template("block"));` which adds a minor flexibility level atop.
mario
jep extract would be possible, too. also it would add more security options which else must be implemented by yourself.
ITroubs
+1  A: 

I'd recommend the PHP plugin standard for a plugin system. See the sample implementation, which also unifies configuration management. It doesn't define a specific plugin API; and it's generally best to go with a hooks system like Wordpress or Drupal (usually function hooks, but you can use static or instantiated callables as well).

mario
A: 

if you're looking to build a custom CMS why don't you pick a php framework and build on top of it. Why build from scratch when you an start with a proven and tested framework. Codeigniter is dead simple and Yii has already built a plugin system into its framework via components and modules: http://www.yiiframework.com/doc/guide/basics.module

Unless you're just trying to learn for yourself, there's really no benefit to building from scratch.

johnW