Zend Framework bindings for Frontal

Having thought further about Frontal, Carl's JS library, I wrote a quick View Helper to make it easier to use it in Zend Framework projects.

It's available to download on Dropbox, it's available under the MIT licence. I'll bung it up on somewhere like GitHub once I work out how Git works.

Basic usage

Before you do anything you'll need to register the helpers in your application.ini:

resources.view.helperPath.Frn_View_Helper = /path/to/Frn/View/Helper

to get it to output anything you'll need to echo the frontal helper at the bottom of the page:

...
<?= $this->frontal() ?>
</body>

By default this will echo nothing! Don't panic, it'll start doing things once you've loaded some stuff into it. The main use-case here is that you're echoing the helper out in some sort of template (Zend_Layout particularly) but pushing configuration into it from your individual views.

Firstly, you can override the path Frontal will use, for instance if there's a page appears under lots of different URLs but you just want one rule that matches it against '/foo':

<? $this->frontal->location('/foo'); ?>

will output:

<script>
$frn.location('/foo');
</script>

Secondly, you can provide some data that frontal might find useful (rather than dump it in global scope). The data is auto-converted to JSON so it's a fairly nice way of feeding data from PHP to JS:

<? $this->frontal->data(array('foo', 'bar')); ?>

will output:

<script>
$frn.data(["foo","bar"]);
</script>

That's pretty much it for now, but it works pretty well and I'm going to be building it into a work project.

Bookmark and Share

Comments

Commenting is currently disabled