Jamal Helper

Published on and tagged with cakephp  helper  jamal  javascript

In the last few days I experimented again with the Javascript MVC framework Jamal. To make its usage a bit easier I wrote a simple helper (you can find it in the downloads section).

As usual, you have to add the helper to the $helpers array of your controller(s) before you can use it:

var $helpers = array('Jamal');

The helper provides two public methods: link() and set().

The link() method is used in the head section of the layout to include all Jamal-related files.

echo $jamal->link();

If DEBUG is greater than 0, it creates something like:

<script type="text/javascript" src="/js/src/jamal.js"></script>
<script type="text/javascript" src="/js/src/models/example.js"></script>
<script type="text/javascript" src="/js/src/plugins/metadata.js"></script>
<script type="text/javascript" src="/js/src/controllers/examples_controller.js"></script>
<script type="text/javascript" src="/js/src/views/examples.js"></script>
<script type="text/javascript" src="/js/src/startup.js"></script>

As soon as you switch DEBUG to 0, it will include the packed version of your scripts (you have to pack them “manually” with the Ant script that comes with Jamal):

<script type="text/javascript" src="/js/dist/jamal_packed.js"></script>
<script type="text/javascript" src="/js/dist/startup.js"></script>

The second method, set(), is used to specify which (Javascript) controller action is executed when the respective view is loaded. So in the view you will do something like:

$jamal->set('MyController', 'myAction');

Additionally, you have to add the variable $jamal_for_layout to the body tag of your layout:

<body <?php echo $jamal_for_layout; ?>>

This will then generate the following code for Jamal:

>body class="jamal {controller:'MyController',action:'myAction',debug:false}">

Happy baking with Jamal :)

5 comments baked

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License