PHP code example of giggleboxstudios / dispatch-handlebars

1. Go to this page and download the library: Download giggleboxstudios/dispatch-handlebars library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

giggleboxstudios / dispatch-handlebars example snippets


  // main layout template file; must contain `{{{content}}}` in <body>
  config('handlebars.layout') = 'layout';

  // set location of .handlbars templates (views and partials)
  config('handlebars.views') = 'path/to/tempaltes';

  // set character encoding for template files; defaults to `UTF-8`
  config('handlebars.charset') = 'utf-8';

  // prefix string to determine partial files, defaults to `_` (underscore)
  config('handlebars.partial_prefix') = '_';

  // [associative array](http://www.php.net/manual/en/language.types.array.php) of tagname and function names
  config('handlebars.helpers') = array('tagName' => 'callback_function');

  // path where compiled templates will be cached (this feature does not work yet)
  config('handlebars.cache') = 'path/to/cached/tempaltes';



  e "app/functions.php";

  //
  // INIT MODEL
  //
  $model = compile_model();


  //
  // CONFIGURE DISPATCH
  //
  config(array(
    'dispatch.url'              =>  'http://localhost/appname'
  , 'handlebars.views'          =>  'app/templates'
  , 'handlebars.layout'         =>  'layout'
  , 'handlebars.partial_prefix' =>  '_'

  , 'handlebars.helpers' => [
        'capitalize' => 'handlebars_capitalize'
      , 'upper'      => 'handlebars_upper'
      , 'lower'      => 'handlebars_lower'
      ]
  ));


  //
  // EXTEND HANDLEBARS
  //
  function handlebars_capitalize($template, $context, $args, $source) {
    return ucwords($context->get($args));
  }

  function handlebars_upper($template, $context, $args, $source) {
    return strtoupper($context->get($args));
  }

  function handlebars_lower($template, $context, $args, $source) {
    return strtolower($context->get($args));
  }


  //
  // DEFINE ROUTES
  //
  on('GET', '/', function () {
    global $model;
    handlebars('homepage', $model);
  });


  //
  // RUN THE APPLICATION
  //
  dispatch();

handlebars();

  config('handlebars.helpers') = array(
      'capitalize'  => 'handlebars_capitalize'
    , 'upper'       => 'handlebars_upper'
    , 'lower'       => 'handlebars_lower'
    );

  // extend handlebars

  function handlebars_capitalize($template, $context, $args, $source) {
    return ucwords($context->get($args));
  }

  function handlebars_upper($template, $context, $args, $source) {
    return strtoupper($context->get($args));
  }

  function handlebars_lower($template, $context, $args, $source) {
    return strtolower($context->get($args));
  }
javascript
{
  " 5.4.0",
    "dispatch/dispatch": ">= 2.6.2",
    "xamin/handlebars.php": "dev-master"
  }
}
javascript
{
  " 5.4.0",
    "dispatch/dispatch": ">= 2.6.2",
    "xamin/handlebars.php": "dev-master",
    "gigglebox/dispatch-handlebars": "dev-master"
  }
}