Skip to content

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

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?

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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