Mustache php gettext ()


I am experimenting with Kostache, "a mustache for a kohana frame."

Is there a way to use simple PHP functions in mustache template files.
I know the logic, and therefore the methods contradict the logical principle of design, but I'm talking about very simple functionality.

For instance:

  • gettext('some text') or __('some text')
  • get base url; in kohan →Url::site('controller/action')
+3
source share
3 answers

Bobthecow is working on an experimental function that will allow you to call the function as a callback.

The higher-order-sections branch of the repository and ticket will open to go with it.

+3
source

"ICanHaz" http://icanhazjs.com/

<script id="welcome" type="text/html">
<p>Welcome, {{<?php echo __('some text') ?>}}! </p>
</script>
0

, Bobachek Mustache Engine. , Template .

Take a look at the following example:

<?php
$mustache = new Mustache_Engine;
# setting data for our template
$template_data = [
    'fullname' => 'HULK',
    'bold_it' => function($text){
        return "<b>{$text}</b>";
    }
];
# preparing and outputting
echo $mustache->render("{{#bold_it}}{{fullname}}{{/bold_it}} !", $template_data);

In the above example, " bold_it " points to our function, which is pasalong with other data in our template. The fullname ' parameter value is passed as a parameter to this function.

Please note that passing parameters is optional in Mustache. You can even call the php function without any parameters, as shown below:

<?php
# setting data for our template
$template_data = [
    'my_name' => function(){
        return 'Joe';
    }
];
# preparing and outputting
echo $mustache->render("{{my_name}} is a great guy!", $template_data); # outputs: Joe is a great guy!

Credits: http://dwellupper.io/post/24/calling-php-functions-for-data-in-mustache-php

0
source

All Articles