djLint
djLint copied to clipboard
[BUG] [Formatter]
Very similar to #370 except for custom blocks and include.
- [x] I'm on the latest version of djLint
- [x] I've searched the issues
- [x] I've read the docs
System Info
- OS: Ubuntu 22.04.5 LTS
- Python Version: Python 3.10.12
- djLint Version: 1.36.1
- template language: Twig
Issue
When using custom blocks story and stories in Twig templates, the indentation of with object/array is collapsed. It also happens within Twig's include tag which can also take a with parameter.
How To Reproduce
Using this .djlintrc file:
{
"custom_blocks": "story,stories",
"indent": "2",
"max_blank_lines": 2,
"profile": "nunjucks"
}
and operating on this template:
{# Define the footer stories #}
{% stories footer with { title: 'Layout/Footer' } %}
{% story default with {
name: 'Footer',
parameters: {
docs: {
description: {
story: 'A footer is a container for various optional components.',
},
},
},
args: {
copyright_notice: '© 2024',
menu_items_housekeeping: [
{
title: 'Accessibility',
url: 'internal:/'
},
{
title: 'Cookies',
url: 'internal:/'
},
{
title: 'Jobs',
url: 'internal:/search'
},
{
title: 'Our Test',
url: 'internal:/'
},
{
title: 'Terms and privacy',
url: 'internal:/'
}
]
},
argTypes: {
copyright_notice: {
name: '© 2024',
type: 'string',
},
menu_items_housekeeping: {
name: 'Housekeeping Menu items',
type: 'object',
defaultValue: [
{
title: 'Accessibility',
url: 'internal:/'
},
{
title: 'Cookies',
url: 'internal:/'
},
{
title: 'Jobs',
url: 'internal:/search'
},
{
title: 'Our Test',
url: 'internal:/'
},
{
title: 'Terms and privacy',
url: 'internal:/'
}
]
}
}
} %}
{% set footer_region %}
{% include "@test/stories/03-layout/footer/regions/region-footer.twig" %}
{% endset %}
{% set housekeeping_region %}
{% include "@test/stories/03-layout/footer/regions/region-housekeeping.twig" %}
{% endset %}
{#
The page variable is passed to the footer template as so it can render
the footer region.
#}
{% set page = {
housekeeping: housekeeping_region,
footer: footer_region,
}
%}
<div class="storybook-html">
{% include '@test/layout/footer.html.twig' with {
page: page,
has_housekeeping: true,
has_footer: true,
} %}
</div>
{% endstory %}
{% endstories %}
The result is:
{# Define the footer stories #}
{% stories footer with { title: 'Layout/Footer' } %}
{% story default with {
name: 'Footer',
parameters: {
docs: {
description: {
story: 'A footer is a container for various optional components.',
},
},
},
args: {
copyright_notice: '© 2024',
menu_items_housekeeping: [
{
title: 'Accessibility',
url: 'internal:/'
},
{
title: 'Cookies',
url: 'internal:/'
},
{
title: 'Jobs',
url: 'internal:/search'
},
{
title: 'Our Test',
url: 'internal:/'
},
{
title: 'Terms and privacy',
url: 'internal:/'
}
]
},
argTypes: {
copyright_notice: {
name: '© 2024',
type: 'string',
},
menu_items_housekeeping: {
name: 'Housekeeping Menu items',
type: 'object',
defaultValue: [
{
title: 'Accessibility',
url: 'internal:/'
},
{
title: 'Cookies',
url: 'internal:/'
},
{
title: 'Jobs',
url: 'internal:/search'
},
{
title: 'Our Test',
url: 'internal:/'
},
{
title: 'Terms and privacy',
url: 'internal:/'
}
]
}
}
} %}
{% set footer_region %}
{% include "@test/stories/03-layout/footer/regions/region-footer.twig" %}
{% endset %}
{% set housekeeping_region %}
{% include "@test/stories/03-layout/footer/regions/region-housekeeping.twig" %}
{% endset %}
{#
The page variable is passed to the footer template as so it can render
the footer region.
#}
{% set page = {
housekeeping: housekeeping_region,
footer: footer_region,
} %}
<div class="storybook-html">
{% include '@test/layout/footer.html.twig' with {
page: page,
has_housekeeping: true,
has_footer: true,
} %}
</div>
{% endstory %}
{% endstories %}