Questions tagged [mustache.php]

A Mustache (logic-less templating system for HTML) implementation in PHP.

mustache.php is an implementation of in PHP. It requires at least PHP 5.2.x.

You can find more information about Mustache on the official website.

Installation

It can be easily installed using :

{
    "require": {
        "mustache/mustache": "2.0.*"
    }
}

An example

<?php
$m = new Mustache_Engine;
echo $m->render('Hello {{planet}}', array('planet' => 'World!'));
// will print: "Hello World!"

Links

94 questions
7
votes
2 answers

PHP Mustache. Implicit iterator: How to get key of current value(numeric php array)

If I have php array like this: $a = array ( 99 => 'Something1', 184 => 'Something2', ); And keys present important information - It can be some constant values, ids e.t.c Then how can I get key of current element from templete. For…
Magix-
  • 71
  • 1
  • 2
6
votes
3 answers
6
votes
2 answers

Server-side or client-side {{mustache}}?

{{mustache}} is, in my opinion, a great template library. The question I face is whether to use it in the client-side, or in the server-side. I am developing an online magazine that will have a main page with one big article and the the rest of its…
eversor
  • 3,031
  • 2
  • 26
  • 46
5
votes
1 answer

How to use user defined function in mustache php

I have set up mustache php in my project. echo $template->render(array( 'data'=>$data, 'lang'=>$lang, 'getMaritialStatus' => function($text, Mustache_LambdaHelper $helper) { return…
Dean Ambrose
  • 183
  • 10
5
votes
1 answer

mustache.java pass json string

I am using mustache.java and wish to plug the json string instead of an object. I am not sure why no one faced this issue before. // works since an 'Example' object is passed in mustache.execute(new BufferedWriter(new FileWriter(objFile)), new…
user1908559
  • 137
  • 10
4
votes
1 answer

Is there a way in mustache to render a block if a section is present without iterating?

I have a section with a header that I want to show only if the array is populated, something like this:

These are the elements in the array

    {{#myArray}}
  • {{name}} - {{value}}
  • {{/myArray}}
How can I render…
Raibaz
  • 9,280
  • 10
  • 44
  • 65
4
votes
1 answer

How to use function wrapper in mustache.php?

I'm starting to work with Mustache on PHP and I don't manage to make wrapper functions to work as debt. I have this template {{#skill_level}} {{#stars}} {{skill_level}} {{/stars}} …
3
votes
3 answers

In Mustache, is there a way to check of the list has items, but not repeat it?

I would like to be able to check if a list is empty, and if it's not print a block, but I don't want to repeat that block for each item. I just want to be able to echo it once. Give this following structure: array( "teasers" => array( …
gdaniel
  • 1,307
  • 2
  • 10
  • 17
3
votes
2 answers

Mustache.php with JSON data throws Catchable fatal error

I've found out you can convert JSON file to PHP arrays and objects and use that output as a data for Mustache.php template engine like this example: PHP Script: require_once('Mustache/Autoloader.php'); Mustache_Autoloader::register(); $mustache =…
Pooria Han
  • 597
  • 1
  • 4
  • 19
3
votes
8 answers

Single/double quotes in ng-init

Let's say we are passing initial data from php to Angular' view by Mustache, and the data is some string that contain quotes, like "Can't delete item". Mustache by default translates the single quote to the ' like: …
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
3
votes
0 answers

How to access current context in php mustache as a function?

Right now I have something like this in my mustache template: {{#render}}{{widget}}{{/render}} And I have a viewModel which contains this code: public function render() { $View = $this->_View; return function($widgetName,…
Evert
  • 2,022
  • 1
  • 20
  • 29
3
votes
1 answer

Render js template through php using mustache

I am using mustache PHP to render my html files and everything works correctly except in one case. There is a situation where I load an html file through an ajax call following this structure: PHP - renders -> HTML - javascript appends -> HTML 2nd…
themazz
  • 1,107
  • 3
  • 10
  • 29
2
votes
0 answers

Handlebars php (LightnCandy\LightnCandy) : each keyvalue pair NULL

I use LightnCandy\LightnCandy to template handlebars in PHP. I want to print some key/value pair on my template (if you have better, thanks to show me :) ). I've try to get key value by : Classic method {{#each my_table as |val key|}} Testing…
Chenille33
  • 93
  • 1
  • 1
  • 10
2
votes
2 answers

Adding parameter to lambda

I am using Mustache's Lambda's to implement translations in my templates. My templates use these kind of tags:

{{#t}}Some translatable text{{/t}}

then, in my data I register a lambda to fetch the translation: $info['t'] = function($text,…
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
2
votes
2 answers

fatal php error: `cannot redeclare function` while using include_once

I have a helper function helper.php with contents: query($sql); } ?> which is included in two files (information.php and commercial.php)…
nluigi
  • 1,263
  • 2
  • 15
  • 35
1
2 3 4 5 6 7