Skip to content

djhtml is not indenting javascript code if not surrounded by script tag #121

@marcodicro-dp

Description

@marcodicro-dp

I have a shell html template that other templates extend from.

In the shell template I have this:

<script type="text/javascript">
  {% block js_includes %}{% endblock %}
</script>

That way, I don't have to include the script tag in every template that extends from the shell.

However, when I run djhtml over those files, the javascript code is not properly indented:

{% block js_includes %}

  $(document).ready(function() {

  $('input:radio[name="reason"][class~="radio-ext"]').change(function (e) {
  var $el = $(e.currentTarget);

  $('input:radio[name="reason"]').each(function(){
  if ($el.attr('id') != $(this).attr('id')) {
  $(this).next().next().addClass('hide');
  } else {
  $(this).next().next().toggleClass('hide');
  }
  });
  });
  })
{% endblock %}

It is properly indented if I add surrounding script tags:

{% block js_includes %}
  <script type="text/javascript">

    $(document).ready(function() {

      $('input:radio[name="reason"][class~="radio-ext"]').change(function (e) {
        var $el = $(e.currentTarget);

        $('input:radio[name="reason"]').each(function(){
          if ($el.attr('id') != $(this).attr('id')) {
            $(this).next().next().addClass('hide');
          } else {
            $(this).next().next().toggleClass('hide');
          }
        });
      });
    })
  </script>
{% endblock %}

How could we fix/workaround this? Can the script tag not be mandatory to properly indent js?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions