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.

Can I pass some parameters in require macro?

See original GitHub issue

I have a header.html template, It is used on every page, and each page has some differences. This is easy to implement if I can pass some parameters in require macro, like:

index.html

@require('path/to/header.html', { name: 'monine' })
// or
@require('path/to/header.html')({ name: 'monine' })

How can I achieve this?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
znlbwocommented, Jul 31, 2017

Hi @emaphp Here’s a new problem with HtmlWebpackPlugin.

header.html

<header>
<% if (name) { %>
<h1><%= name %></h1>
<% } %>
</header>

page-a.html

@require('path/to/header.html', { "name": 'monine' })

page-b.html

@require('path/to/header.html')

There will be throw a error from HtmlWebpackPlugin: Template execution failed: ReferenceError: name is not defined

Because of require macro does not provide arguments in page-b.html. but header.html needs it…

Or should I commit this issue to HtmlWebpackPlugin?

0reactions
idudinovcommented, Oct 18, 2018

Hi, the thread is quite old but still open, just came across it and wanted to share my solution for the problem of Template execution failed: ReferenceError: name is not defined. So the workaround is just to ensure the variable exist somewhere before usage:

<% const theTile = (typeof title !== 'undefined' && title) || 'Default Title' %>

<title><%= theTitle %></title>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass Arguments to a Macro Called from a Button or Sheet in ...
To assign a macro that you pass arguments to a button, shape, image, or any object, you first right-click that object and click...
Read more >
Passing Simple and Complex Parameters In and Out of Macros
This is fine for simple macros, but when there are multiple parameters, keyword parameters can be helpful. Keyword parameters require the macro call...
Read more >
Can I pass Parameters in Execute macro Activity If Yes then ...
I am using a Execute macro activity in uipath studio but without passing parameter it is working fine and call a macro performing...
Read more >
how to pass a parameter with macro variables into macro
Pass the names not the value. Then you don't have to worry about quoting in the macro call. Also you can't name a...
Read more >
Macro Arguments (The C Preprocessor)
Function-like macros can take arguments, just like true functions. To define a macro that uses arguments, you insert parameters between the pair of ......
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