Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad indentation in case of nested partials #349

Open
ggunti opened this issue Apr 1, 2021 · 0 comments
Open

Bad indentation in case of nested partials #349

ggunti opened this issue Apr 1, 2021 · 0 comments

Comments

@ggunti
Copy link

ggunti commented Apr 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant