django-pattern-library icon indicating copy to clipboard operation
django-pattern-library copied to clipboard

Impossible to override context in for a child template

Open thibaudcolas opened this issue 5 years ago • 7 comments

In GitLab by @m1kola on Dec 14, 2017, 11:38

If you have a some_page.html&some_page.yaml and include_me.html&include_me.html and some_page.html includes include_me.html.

some_page.yaml with something like:

context:
  page:
    pk: 1
    title: "my title"

and include_me.yaml with something like:

context:
  page:
    title: "Title from include"

Title from include will appear on both patterns. It's impossible to override single key in some_page.html

cc @bcdickinson

thibaudcolas avatar Feb 19 '20 07:02 thibaudcolas

In GitLab by @m1kola on Dec 14, 2017, 11:42

Hm. Actually, probably my description is incorrect... I'll double check later

thibaudcolas avatar Feb 19 '20 07:02 thibaudcolas

This feels like something that should at least documented if indeed an issue.

thibaudcolas avatar Feb 24 '20 20:02 thibaudcolas

To do this properly, we could take a leaf out of docker-compose's book and steal its MergeDict stuff: https://github.com/docker/compose/blob/df05472bcc6f1596e519a1e02f01cebd4e160011/compose/config/config.py#L984

bcdickinson avatar Sep 26 '20 11:09 bcdickinson

Mentioned in the docs as of #131.

thibaudcolas avatar Oct 30 '20 08:10 thibaudcolas

Closed in favour of #138.

thibaudcolas avatar Jan 24 '22 10:01 thibaudcolas

I'm going to repoen this, as it's not a strict duplicate. This is concerning the hiding of context values set in outer contexts by those set in included/extended template contexts, whereas #138 is about controlling the output of tags that are not explicitly called by included/extended template in inner contexts (I know, this makes my brain hurt too).

bcdickinson avatar Dec 09 '22 11:12 bcdickinson

I've come across https://github.com/clarketm/mergedeep which might be useful here.

bcdickinson avatar Dec 09 '22 11:12 bcdickinson