hygen icon indicating copy to clipboard operation
hygen copied to clipboard

Nested variable in conditional rendering raises error

Open musaffa opened this issue 5 years ago • 5 comments

I'm trying to prevent a template generation for a certain condition:

---
to: "<%= locals.image ? 'apps/operations/<%= h.inflection.pluralize(name) %>/image.rb' : null %>"
---

There's a nested template literal in the file location. Running the generator raises the following error: Error: Could not find matching close tag for "<%=". It looks like an invalid ejs syntax. The documentation does not cover nested variable in a conditional rendering. How to solve this problem?

musaffa avatar Mar 22 '19 00:03 musaffa

Something like this should work:

---
to: "<%= locals.image ? 'apps/operations/' + h.inflection.pluralize(name) + '/image.rb' : null %>"
unless_exists: true
---

lewebsimple avatar Mar 22 '19 01:03 lewebsimple

Even better:

to: "<%= locals.image ? `apps/operations/${h.inflection.pluralize(name)}/image.rb` : null %>"

This is such a common thing in template generation that I think a simpler option like skip_if will be very handy.

musaffa avatar Mar 22 '19 06:03 musaffa

Hi,

I am having the same issue with

---
to: "<%= group === 'panels' ? 'src/client/app/components/<%= group %>/<%= Name %>/stores/<%= name %>Store.js' : null %>"
unless_exists: true
---
Error: Could not find matching close tag for "<%=".
Hygen v4.0.11

I do not need to use pluralize in this case, I just need to apply the variables in the path :( . Any idea>?

haven't found anything in the docs

Vanals avatar Oct 10 '19 09:10 Vanals

You're nesting ejs tags, instead use regular js

---
to: "<%= group === 'panels' ? `src/client/app/components/${group}/${Name}/stores/${name}Store.js` : null %>"
unless_exists: true
---

anithri avatar Oct 11 '19 23:10 anithri

Hi,

I am having issue on

Exception Message: {"metadata":{"error":true},"payload":{"code":412,"errors":[],"message":"Invalid nesting of ocx_if and ocx_loop"}}

Could you please help?

pk03061987 avatar Feb 27 '21 04:02 pk03061987