laravel-handlebars icon indicating copy to clipboard operation
laravel-handlebars copied to clipboard

Bad indentation in case of nested partials

Open ggunti opened this issue 3 years ago • 0 comments

I have 3 handlebars template files inside 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 bug

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>

In case of handlebars with javascript, the indentation works as expected.

The handlebars.php config 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,

];

ggunti avatar Apr 01 '21 18:04 ggunti