示例#1
0
 public function testCombinations()
 {
     $contents = '{{#if merchants.length~}}
         {{{query.profile_id~}}}
         {{#each merchants~}}
             {{profile_name~}}
             {{#if ../query.profile_id.length~}}
                 Yes1
             {{~else~}}
                 {{#if ../query.profile_name.length~}}
                     {{!-- This Works --~}}
                     Yes2
                 {{~else~}}
                     NO2
                     {{~query.profile_id~}}
                 {{/if~}}
             {{/if~}}
         {{/each~}}
     {{else~}}
     NO1
     {{~/if}}';
     $template = $this->handlebars->compile($contents);
     $results = $template(array('merchants' => array(array('profile_name' => 'John'), array('profile_name' => 'Jane'), array('profile_name' => 'Jill')), 'query' => array('profile_id' => '123', 'profile_name' => 'John')));
     $this->assertEquals('123JohnYes1JaneYes1JillYes1', $results);
 }
示例#2
0
 public function testAddPartial3()
 {
     $runtime = new Handlebars\Runtime();
     $runtime->addPartial("foo", "This is {{ foo }}");
     $runtime->addPartial("bar", "Foo is not {{ something }}");
     $handlebars = new Handlebars\Handlebars($runtime, call_user_func($this->compilerFactory, $runtime), $this->dataFactory);
     $template = $handlebars->compile("{{> foo }} ... {{> bar zoo something='Amazing'}}");
     $result = $template->render(array("foo" => "FOO", "bar" => "BAR", "zoo" => array("bar" => "ZOO")));
     $this->assertEquals("This is FOO ... Foo is not Amazing", $result);
 }
示例#3
0
 public function testMustache()
 {
     $template = $this->handlebars->compile('{{#foo}}{{this}}{{/foo}}');
     $result = $template(array('foo' => array(1, 2, 3)));
     $this->assertEquals('123', $result);
 }