EzDevInfo.com

MtHaml

Multi target HAML (HAML for PHP, Twig, <your language here>)

Mthaml variable inside class

I'm trying to declare a variable inside a class in mthaml, from what I've read this should do it:

$columns = 3
%div{:class => "columns large-#{$columns}"}

However this prints:

<div class="columns large-">

Source: (StackOverflow)

running load_class on mthaml

I'm trying to use load_class to load mthaml as I understood it's necessary for performance reasons.

This is the MtHaml library. https://github.com/arnaud-lb/MtHaml

It's namespaced everywhere so getting it working with load_class natively hits the first hurdle. Then it gets instantiated through Autoloader.php which does

namespace MtHaml;

class Autoloader
{
    static public function register()
    {
        spl_autoload_register(array(new self, 'autoload'));
    }

    static public function autoload($class)
    {
        if (strncmp($class, 'MtHaml', 6) !== 0) {
            return;
        }

        if (file_exists($file = __DIR__ . '/../' . strtr($class, '\\', '/').'.php')) {
            require $file;
        }
    }

I'm trying

load_class('Autoloader', 'libraries/MtHaml', '');

But that gives me Fatal error: Class 'Autoloader' not found

Then if I try

load_class('MtHaml\Autoloader', 'libraries/MtHaml', '');

I get Unable to locate the specified class: MtHaml\Autoloader.php

Right now the only way I got this working is by calling it like so

    require_once __DIR__ . '/../libraries/MtHaml/Autoloader.php';
    MtHaml\Autoloader::register();
    $haml = new MtHaml\Environment('php');
    $rendered = $haml->compileFile($haml_file, $haml_cache_path);

The problem being this piece of code is ran anytime I call my $this->load->view in code igniter so I understood load_class was needed to optimize performance as in one controller I could be calling $this->load->view several times.

How do I use load_class with this?


Source: (StackOverflow)

Advertisements

Symfony2 mthaml syntax

Situation: I have to place many scripts in "javascripts" native twig block.

- javascripts 'assets/js/jquery.js' 'assets/js/some1.coffee' 'assets/js/some2.coffee' ...  'assets/js/someN.coffee' output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

How to put scripts each in particular line?

Example:

- javascripts 'assets/js/jquery.js' 
'assets/js/some1.coffee' 
'assets/js/some2.coffee' ...  
'assets/js/someN.coffee' 
output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

Error:

An exception has been thrown during the compilation of a template ("Illegal nesting: nesting within interpolated string is illegal in ... bla bla bla ... layout.html.haml".

Please don't offer assets/js/*


Source: (StackOverflow)

executing functions in fuelphp mthaml templates

I installed parser package for fuelphp to have mthaml (https://github.com/arnaud-lb/MtHaml) support in templates. So I created a tamplate and I don't understand how can I run fuelphp helper functions in the mthaml templates.

I'm running haml/twig templates

At example:

{% haml %}
!!!
%body
  .login-box

   = Form::open('/test/')

Will show error:

An opened parenthesis is not properly closed. Unexpected token "punctuation" of value ":" ("punctuation" expected with value ")") in "login.twig" at line 6

So question is How can I run fuelphp functions inside the mthaml templates? Echoing array elements or strings with = array.some_value or = string works fine.

bump.


Source: (StackOverflow)

mthaml processing my php variables inside :javascript

I'm using a PHP port of MTHAML which uses the exact same syntax. How can I tell MTHAML to not touch my variables when I use them inside

https://github.com/arnaud-lb/MtHaml

For instance this

  :javascript
      if (#{$response)} !== "") {
        show_error("#{$response}");
      }

Gets converted to this

  <script type="text/javascript">
  //<![CDATA[
      if (<?php echo htmlspecialchars(escape("$response"),ENT_QUOTES,'UTF-8'); ?> !== "") {
        show_error("<?php echo htmlspecialchars($response,ENT_QUOTES,'UTF-8'); ?>");
      }
  //]]>
  </script>

So my PHP boolean variables show up as blank in the rendered javascript, or if my php variable is a string with quotes, the quotes end up being converted to &quot.


Source: (StackOverflow)