Skip to content

Assets of components not output if render_to_string is used #163

@joshuadavidthomas

Description

@joshuadavidthomas

I've got a django-tables2 table, where in one of the columns I'm rendering to string another partial template that has a component defined in it. It's a modal, so I've got a modal.js alongside it for defining the behavior. Based on the scanning logic currently, there's no way for the parent table template to know it's using a certain component.

In [5]: components._template_usage
Out[5]:
defaultdict(set,
            {PosixPath('/app/templates/base.html'): {'indicator'},
             PosixPath('/app/templates/invoices/partials/adjust_acres.html'): {'description.details',
              'description.list',
              'description.term',
              'modal',
              'modal.trigger'},
             PosixPath('/app/templates/invoices/partials/adjust_rate.html'): {'description.details',
              'description.list',
              'description.term',
              'modal',
              'modal.trigger'}})

So either the adjust_acres.html or adjust_rate.html have the component defined and if I was just rendering that partial, the {% bird:js %} tag would render the correct modal.js tag. But since I'm rendering it ahead of time before rendering the actual page or table within that page, it doesn't output anything.

Currently getting around this by including the component in a comment in the main template, so it doesn't actually get render but does get picked up by the template scanning:

  {# comment #}
  {% bird modal %}
  {% endbird %}
  {# endcomment #}

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions