Closed myovchev closed 3 years ago
(I had to use an https URL to check it out but then I got it.)
This works if you write:
{% import "helper.macro.html" as helper with context %}
However "apos" should probably be injected via "addGlobal" rather than as a template context variable.
Not sure whether this should be the case for "data".
On Wed, Jan 20, 2021 at 5:38 AM Miro Yovchev notifications@github.com wrote:
To Reproduce
git clone git@github.com:myovchev/a3-helpers.git && cd $_
Detailed instructions are available in the README https://github.com/myovchev/a3-helpers. I'm providing a copy here as well:
- Be sure you have running mongodb on default port. Database a3-helpers will be auto-created.
- Run the project in dev mode (npm i && npm run dev). Ignore warnings, no need of user/session secret.
- You should see home page rendered with additional Helper Test section.
- Open modules/@apostrophecms/home-page/views/page.html and uncoment around line 23
{{ helper.render("Same helper called from inside of a macro will fail") }}
- You should see error page, look at the CLI output.
Expected behavior
Execute the module nunjucks helper without an error. Describe the bug
Registered via a3 module helpers are not available inside of any nunjucks macro. Details
An example call apos.moduleName.someHelper() raises error: Error: Unable to call apos["moduleName"]["someHelper"], which is undefined or falsey
Version of Node.js: v12.8.1
Server Operating System:
lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal
No docker involved. Node env provided by nvm.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/apostrophe/issues/2692, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27JKLTOS3G4QCF424G3S22XDPANCNFSM4WKO2J5Q .
--
THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his
See PR:
https://github.com/apostrophecms/apostrophe/pull/2698
With this PR "with context" is not required.
Solution has been merged to the 3.0 branch. Thanks for raising the issue!
To Reproduce
Detailed instructions and info are available in the README. I'm providing a copy here as well:
a3-helpers
will be auto-created.npm i && npm run dev
). Ignore warnings, no need of user/session secret.Helper Test
section.modules/@apostrophecms/home-page/views/page.html
and uncoment around line 23<p>{{ helper.render("Same helper called from inside of a macro will fail") }}</p>
Changes made to the original a3 boilerprate to reproduce the issue:
helper.include.html
,helper.macro.html
,plain.macro.html
inmodules/@apostrophecms/home-page/views/
modules/@apostrophecms/home-page/views/page.html
to include the macros and render additional section reproducing the issue in questionalias
and dummy helper inmodules/@apostrophecms/home-page/index.js
app.js
- shortName renamed toa3-helpers
package.json
: removed build fromnpm run dev
command, addedpostinstall
for initial build and better startup timeExpected behavior
Execute the module nunjucks helper without an error.
Describe the bug
Registered via a3 module helpers are not available inside of any nunjucks macro.
Details
An example call
apos.moduleName.someHelper()
raises error:Error: Unable to call
apos["moduleName"]["someHelper"], which is undefined or falsey
Version of Node.js: v12.8.1
Apostrophe CMS version 3.0.0-alpha.3
Server Operating System:
No docker involved. Node env provided by
nvm
.