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.

Empty nested variables breaking templates when used inside components

See original GitHub issue
  • Maizzle Version: 4.0.0
  • Node.js Version: 16.5.3

Hi,

It’d be really handy if we were able to build templates locally that include nested variables e.g. page.myVariable.myNestedVariable. Currently we’re having to insert these into our maizzle config when developing locally, e.g:

const config = {
  ...
  myVariable: {
  }
}

If maizzle serve used lodash/get (or similar) for getting template variables that would save us a lot of hassle. Alternatively, if maizzle serve supported optional chaining that would also help, but even on new versions of node optional chaining doesn’t seem to do anything, the templates still break.

Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jebaxcommented, Jun 9, 2022

I just tested in a fresh new project and simply replaced the contents of promotional.html with this:

<extends src="src/layouts/main.html">
  <block name="template">
    {{ page.foo?.bar || 'default' }}
  </block>
</extends>

Could be related to outdated dependencies / your yarn problem perhaps?

Tried again and it worked, I think it was due to me not deleting node_modules before reinstalling like you say! Don’t think it’s related to that other issue though.

Thanks for your time anyway, I appreciate it

0reactions
jebaxcommented, Jun 9, 2022

Yeah, it’s not intentional, just the way posthtml-modules (what we use for components) works.

A way around it is to use a fallback of some kind, or optional chaining:

<!-- v-fill.html -->
<content></content>

{{ page.x?.y.z }}

Ah ok, thanks for the info!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Templates Maintain Lexical Binding In Angular 7.2.13
Templates in Angular work like lexically-bound HTML fragments. This allows them to access variables declared in a parent scope as well as ...
Read more >
Template literals (Template strings) - JavaScript | MDN
Nesting templates​​ In certain cases, nesting a template is the easiest (and perhaps more readable) way to have configurable strings. Within a ...
Read more >
Template::Manual::Variables
When the variable is used, the Template Toolkit will automatically call the subroutine, passing any additional arguments specified. The return ...
Read more >
Helm optional nested variables - kubernetes - Stack Overflow
A technique I've used successfully is to use a variable to hold the value of the outer block, which then can use templating...
Read more >
Where variables can be used - GitLab Documentation
As it's described in the CI/CD variables documentation, you can define many different variables. Some of them can be used for all GitLab...
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