zordius / lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
https://zordius.github.io/HandlebarsCookbook/
MIT License
608 stars 76 forks source link

Bad indentation in case of nested partials #349

Open ggunti opened 3 years ago

ggunti commented 3 years ago

The PHP Code:

I am using the laravel-handlebars package which under the hood uses this package (it is just wrapped for laravel framework).

I have 3 handlebars template files inside the views/templates directory:

test.hbs:

<div>
  <p>Hello</p>
  {{> testPartial}}
</div>

testPartial.hbs:

<div>
  <p>This is inside a partial</p>
    {{> testPartial2}}
</div>

testPartial2.hbs:

<div>
  <p>This is inside partial 2</p>
</div>

The config/handlebars.php file:

<?php

use ProAI\Handlebars\Support\LightnCandy;

return [

    /*
    |--------------------------------------------------------------------------
    | Flags
    |--------------------------------------------------------------------------
    |
    | Set Lightncandy flags here. See https://github.com/zordius/lightncandy
    | for more information.
    |
    */

    'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_HANDLEBARSJS_FULL,

    /*
    |--------------------------------------------------------------------------
    | File Extensions
    |--------------------------------------------------------------------------
    |
    | All file extensions that should be compiled with the Handlebars template
    | engine. Unless you specify your own partial resolver the package will
    | look for files in Laravel's view storage paths.
    |
    */

    'fileext' => [
        '.handlebars',
        '.hbs',
    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Busting
    |--------------------------------------------------------------------------
    |
    | Using nested Handlebars partials makes is difficult to determine if the
    | view at a given path is expired. Therefore you can specify environments
    | where the cached views will be recompiled on each request.
    |
    */

    'development_environment' => [
        'local',
    ],

    /*
    |--------------------------------------------------------------------------
    | Partials
    |--------------------------------------------------------------------------
    |
    | https://github.com/zordius/lightncandy#partial-support
    |
    */

    'partials' => [],
    'partialresolver' => false,

    /*
    |--------------------------------------------------------------------------
    | Helpers
    |--------------------------------------------------------------------------
    |
    | https://github.com/zordius/lightncandy#custom-helper
    |
    */

    'helpers' => [],
    'helperresolver' => false,

    /*
    |--------------------------------------------------------------------------
    | Language Helpers
    |--------------------------------------------------------------------------
    |
    | Use this option, if you want to use the language helpers in a template.
    | You can use a {{lang ...}} and {{choice ...}} helper. Both have the same
    | behaviour like the @lang and @choice Blade directives.
    |
    */

    'language_helpers' => true,

    /*
    |--------------------------------------------------------------------------
    | Optional Raw Output
    |--------------------------------------------------------------------------
    |
    | If this option is set to true, you can pass a $raw variable to the data
    | array. If $raw is true, then the template will be returned without
    | rendering in raw format. This is helpful if you want to use a Handlebars
    | template clientside with javascript.
    |
    */

    'optional_raw_output' => true,

    /*
    |--------------------------------------------------------------------------
    | Translate Raw Output
    |--------------------------------------------------------------------------
    |
    | If language_helpers and optional_raw_output are set to true, this option
    | can also set to true. If so, the translation helpers will also be
    | rendered for the raw output.
    |
    */

    'translate_raw_output' => true,

];

The Issue:

When I execute return view('templates.test');, I get:

<div>
  <p>Hello</p>
  <div>
    <p>This is inside a partial</p>
      <div>
      <p>This is inside partial 2</p>
    </div>
</div>
</div>

But I should get:

<div>
  <p>Hello</p>
  <div>
    <p>This is inside a partial</p>
      <div>
        <p>This is inside partial 2</p>
      </div>
  </div>
</div>

So, the problem is that the indentation is not working properly in case of nested partials.