question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to reassign include arguments locally within the include file itself

See original GitHub issue

Related 11ty issue: https://github.com/11ty/eleventy/issues/2000

Steps to reproduce:

  1. Create an include that accepts one argument.
  2. Reassign the argument locally within the include.
  3. Render the argument.
  4. Invoke the include and specify a value for the argument.
  5. Observe that the value does not get overridden.

Example:

parent.html

{% include child.html color: "red" %}

child.html

{% assign color = "green" %}{{ color }}

Expected behavior: the output is green.

Observed behavior: the output is red.

If it’s okay, I’d like to take a crack at fixing this (if you think it’s realistic for a first-time contributor). I have a failing test locally to confirm, but I’ll need to figure out where in the code it’s breaking.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
pdehaancommented, Oct 31, 2021

@AleksandrHovhannisyan I’m pretty sure 11ty v1 (beta) supports the render tag as well (although it’s been a while since I’ve played with that).

Although I do see that https://github.com/11ty/eleventy/blob/19b4884e83e420a3b42f334aa922140f9cb18353/package.json#L107 is pinned to a very specific version of liquidjs, so we might need to tweak that line from the 11ty side (or else you can try manually installing the latest liquidjs locally and then try setting your own custom library instance.


UPDATE: Filed https://github.com/11ty/eleventy/issues/2059 from the 11ty side to bump liquidjs version back to latest.

1reaction
harttlecommented, Oct 31, 2021

After digging into Liquid and LiquidJS (I wrote this part long time ago and it takes me quite a while to figure it out, sorry for this), I find that:

include and layout are legacy tags which does not provide Context separation. In both Shopify/Liquid and LiquidJS, {% assgin %} in {%include%} files assigns to its parent template, thus will not hide include arguments. So it’s by design and that’s why {%include%} tag is deprecated.

render enforces Context separation by creating a new Context when render partials, but it has a bug resulting in {% assign %} inside {%render%} also not hiding render arguments. It’s definitely a bug and not consistent with Shopify/Liquid, I updated @AleksandrHovhannisyan 's PR and fixed this bug on v9.28.4, check it out!

layout is implemented just like include and still not works for now, I’ll consider provide a substitution for layout too if someone actually needs that. Feel free to open a feature request issue for it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c - __FILE__ macro shows full path - Stack Overflow
Example: So for my Jenkins builds I will add -ffile-prefix-map=${WORKSPACE}/=/ , and another to remove the local dev package install prefix.
Read more >
Packer.nvim - GitHub
Uses native packages, supports Luarocks dependencies, written in Lua, ... required if you have packer configured as `opt` vim.cmd [[packadd packer.nvim]] ...
Read more >
Troubleshooting Windows Subsystem for Linux | Microsoft Learn
File a new issue. If you have found a problem with WSL and there does not appear to be an existing issue, you...
Read more >
Best practices for writing Dockerfiles - Docker Documentation
Best practices for writing Dockerfiles. This document covers recommended best practices and methods for building efficient images.
Read more >
Configuration and credential file settings - AWS Documentation
The AWS CLI stores sensitive credential information that you specify with aws configure in a local file named credentials , in a folder...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found