torchbox / torchbox/django-pattern-library

Pass context to template tag override

Open
#193 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

django enhancement help wanted
Dominant language
Python
Stars
423
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Is your proposal related to a problem?

When overriding a template tag you have the option to render another template in its place.

Currently, only the existing template context (from the yaml file) of that template will be taken into account.
It would be nice to have the option to pass context overrides to the template.

Describe the solution you'd like

E.g. in a template override like this:

tags:
  include_block:
    tl with size="2xl" heading_level=sub_heading_level:
      template_name: "atoms/teaser-link/teaser-link.html"

I would love to be able to do something like this:

tags:
  include_block:
    tl with size="2xl" heading_level=sub_heading_level:
      template_name: "atoms/teaser-link/teaser-link.html"
      context_override: 
        size: "2xl"
        heading: "Overrding the heading form the template context yaml"
Describe alternatives you've considered

An alternative is to create specific variants of the template I really want to use. That has the tendency to clutter the template directly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the template tag override implementation and its existing tests, then trace how the YAML template context is applied when rendering a replacement template. Compare that flow with the proposed context_override mapping and add coverage showing that supplied values are available in the rendered template without breaking existing context behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.