0

I am using jQuery.tmpl Templates to render data that i fetch via ajax. Still, sometimes layouts are rendered on the server (i.e. for entry-points, fallback and caching) so the templates used by jQuery.tmpl are very much the same as the Views used by Zend Framework which is use as a backup.

The problem is that Zend uses PHP tags inside HTML while jQuery uses a template language.

Where the ZF View looks like this:

<div id="Item_<?= $this->item->id ?>" class="Items">
  <h2><?= $this->item->title ?></h2>
  <p><?= $this->item->teaserText ?></p>
</div>

the jQuery Template looks like this:

<div id="Item_${id}" class="Items">
  <h2>${title}</h2>
  <p>${teaserText}</p>
</div>

Is there an easy to integrate but still flexible template engine i could use to parse the jQuery templates? Has anyone any experience with using Smarty for such a solution?

1 Answer 1

1

You can extend Zend_View to use the same syntax as jQuery templating engine, this way both template would be the same.

There is a section in the manual describing how to use or implement your own template engine.

3
  • Yes, i could rewrite Zend_View couldn't i? But since i try to avoid code repetition to avoid wasting time i'd rather not do that ;D Dec 21, 2011 at 13:12
  • @AndreschSerj: if you write your own template you should be able to use the same syntax, so no more duplication?
    – RageZ
    Dec 21, 2011 at 13:13
  • Yes, but then i would have written my own Template engine right? And re-building the wheel is exactly what code repetition is, which is why I specifically asked for a template engine to use here. Dec 21, 2011 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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