As a learning experience, and as project, I am attempting to write a CMS module for ZF2. One of the functionality I would like to have is the possibility of adding dynamic contents in the pages by calling PHP functions in the view scripts.

However, I do not want to give the users freedom in writing PHP code directly inside the page content, but rather implement custom view helpers (or widgets) to handle logic. For example: calling partial, partialLoop, url, etc. specifying arguments and all.

I liked the idea of extending Markdown but this would get complicated when trying to add custom CSS class to elements, etc.

Then I had the idea of simply doing a preg_replace on some patterns. For example, the string :

### partialLoop:['partials/display.phtml',[{id:'p1',price:4.99},{id:'p2',price:12.34}]] ###

would be replaced by

<?php echo $this->partialLoop('partials/display.phtml', array(array('id'=>'p1','price'=>4.99),array('id'=>'p2','price'=>12.34))) ?>

Obviously, there would be some caching done so the page content is not rendered everytime. Does this sound good?

If not, what would be a good way of doing this? Or is there a project already being developed for doing this? (I'd like to avoid heavy third party libs and something fairly or fully compatible with ZF2 would be nice.)


closed as primarily opinion-based by gnat, user40980, Michael Kohne, thorsten müller, Kilian Foth Oct 6 '13 at 14:35

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.


You should check out a template library called Twig. It would integrate well with ZF2 (many people have done it) and you can extend it to do anything you want or to limit anything you want.

Not the answer you're looking for? Browse other questions tagged or ask your own question.