@baris This worked like a charm. Thank you!
magnusvhendin
Posts
-
Template helpers not working in in NodeBB v2 -
Unable to override scripts@julian This worked great. I did this in my main client file (like persona.js).
require(['hooks'], (hooks) => { hooks.on('filter:script.load', (data) => { const replaceMap = { register: { target: 'forum/register', with: 'replacement/register', }, }; const replace = replaceMap[data.tpl_url]; if (replace) { const index = data.scripts.indexOf(replace.target); if (index > -1) data.scripts[index] = replace.with; else data.scripts.push(replace.with); } return data; }); });
Then I can just add my scripts that I want to replace to the replaceMap object.
-
Unable to override scriptsMigrating to NodeBB v2 I came across an issue that I cannot resolve. In my theme/plugin I override two scripts because I want to write my own logic for two pages:
- register
I get this error:
uncaughtException: EEXIST: file already exists, symlink '../../../../node_modules/[PLUGIN/THEME NAME]/lib/client/register.js'
Any ideas on how to get around this?
-
Template helpers not working in in NodeBB v2I get the following error client side:
Uncaught TypeError: can't access property "registerHelper", Benchpress is undefined
-
Template helpers not working in in NodeBB v2I'm at the moment adapting my plugins for v2 and ran into an issue with template helper functions. I've until now included them as below, so they work both when rendered on the server and the client.
'use strict'; /* globals */ (function (factory) { if (typeof module === 'object' && module.exports) { factory(require.main.require('benchpressjs')); } else { require(['benchpress'], factory); } }((Benchpress) => { const number_of_answers = (data) => { const replies = data.postcount - 1; switch (replies) { case 0: return 'No comments'; case 1: return '1 comment'; default: return `${replies} comments`; } }; const customHelpers = { number_of_answers, }; function register() { Object.keys(customHelpers).forEach((helperName) => { Benchpress.registerHelper(helperName, customHelpers[helperName]); }); } register(); if (typeof module === 'object' && module.exports) { module.exports = customHelpers; } }));
This has worked great but now that I'm running v2 (2.0.0) it only works server side. I'm including the file in
plugin.json
under scripts,"lib/helpers.js"
.One guess is that I should move it to modules as other client scripts, but I'm not sure how I should do that with template helpers.
Appreciate all help.
-
Why isn't email required anymore?@julian I agree with you on the extra steps (TOS etc), but just not on the email bit.
For me these are the logical paths:
Do not require email
- Input username and password.
- Click register
- Fill in optional information
Require email
- Input username, email and password
- Click register
- Fill in optional information
This makes it very obvious what is and what isn't optional.
That said. It's obviously up to you but I don't think it would be a huge amount of work to do this. Is it something that you would approve as a PR or do you want to keep it as is?
-
Why isn't email required anymore?@crazycells That's exactly what I mean. The way it was implemented now is very confusing. I get the need to remove email as a factor (GDPR etc), but I don't understand the way it was implemented. And for some forums emails could be crucial, so why put it after registration? I know it's not technically after registration but, still not where expected.
No where else have I encountered a registration where you don't input your information all at once. I even feel that the TOS could be a checkbox with a link to the information.
But in the end it's the decision of the NodeBB team and I don't want to nag about it. I'm just interested in the reasoning.
-
Why isn't email required anymore?Or to be more precise, why was this moved to the interstitials step in the registration?
I'm referring to this commit.
I don't really see why this was needed. If the forum requires a valid email address, why not just show that at registration, and not as an after thought? Even if you tick "Require new users to specify an email address" at /admin/settings/user#user-registration, you only get prompted in the optional email input during the interstitials.
-
Test fail for missing translation key@julian Okay, I'll do that. Thanks!
-
Test fail for missing translation keyOkay I now found this.
So does that mean that I should suggest this key be added and wait with my request or that I should push it with language in template and update at a later point?
-
Test fail for missing translation keySo I'm creating a pull-request for NodeBB core and one of the requests in the contribution guide is to make sure that the tests all pass. I had some issues setting it up properly but now it works except for one part of the tests.
This one to be precise. As I understand it tells me to add my newly created translation key in all language files. I'm using the
en-GB
folder. This file to be precise,/admin/settings/notifications.json
.So my question is, how to I make sure that it gets put in all other language folders, in the correct file?
Is there a simple way of generating the files or do I need to do it manually? Do I skip this step and just make sure that the other tests work? Are these files generated somehow, using Transifex?
I can also add it to
en-US
andsv
files, but that is the extent of my language abilities. -
Unable to load template@julian I'm actually using uBlock so disabling it did the trick. The simple solution is probably to name it something else, like statistics or something. No big deal. Either way, thanks for the assist.
@gotwf I only have uBlock Origin installed but haven't changed any settings whatsoever. So I guess that would be the first option. I'll definitely check the logging options. Thanks!
-
Unable to load template@julian Oh wow that actually fixed it. Firefox is my primary browser and I do have an extra layer of tracking protection installed. At least now I know what the cause is, and can move on to troubleshooting it.
Any reason you thought of that?
-
Unable to load templateAlso works fine in Safari.
-
Unable to load template@pitaj Private browsing doesn't solve it. And the two scripts you mentioned are where they should be.
Chrome (inkognito) still works. Firefox (private browsing) still doesn't work.
-
Unable to load template@pitaj This is the template:
<div class="row"> <div class="col-xs-12 col-md-2 no-print"> <div class="row"> <div class="col-xs-12 col-sm-6 col-md-12 form-group"> <label for="start">[[admin/advanced/events:filter-start]]</label> <input type="date" component="analytics/input-start" name="start" value="{query.start}" class="form-control" /> </div> <div class="col-xs-12 col-sm-6 col-md-12 form-group"> <label for="end">[[admin/advanced/events:filter-end]]</label> <input type="date" id="end" component="analytics/input-end" value="{query.end}" class="form-control" /> </div> <div class="form-group col-xs-12"> <button class="btn btn-primary" component="analytics/apply-btn">Apply</button> </div> <div class="form-group col-xs-12"> <button class="btn btn-primary" component="analytics/view-activity-report">Activity report</button> </div> </div> </div> <div class="col-xs-12 col-md-10" id="events-chart"> <canvas></canvas> </div> </div> <div class="row"> <div class="col-xs-12" id="companies-chart"> <canvas></canvas> </div> </div>
The two canvases are used to draw diagrams with chart.js included from NodeBB core.
The template is located in
static/templates/community/analytics.tpl
To me though, the error suggests that it tries to load a js file that it assumes exists (and it does) but then fails and halts everything. It's also seems a bit odd that it works fine on Chrome, but not Firefox.
-
Unable to load template@baris The plugin is not open source as of yet. It hopefully will be in the future but right now it's not ready.
This is the plugin.json:
{ "id": "nodebb-plugin-community-analytics", "library": "./library.js", "hooks": [ { "hook": "static:app.load", "method": "init" }, { "hook": "static:api.routes", "method": "addRoutes" }, { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, { "hook": "action:events.log", "method": "writeEventLog" } ], "staticDirs": { "static": "./static" }, "less": [ "static/style.less" ], "modules": { "chroma.js": "static/external/chroma.min.js" }, "scripts": [ "static/lib/communityAnalytics.js", "static/lib/globalAnalytics.js", "static/lib/activityReport.js", "static/lib/chartHelpers.js" ], "acpScripts": [ "static/lib/admin.js" ], "templates": "static/templates", "languages": "languages" }
This is in the
controllers.js
-file.Controllers.renderCommunityAnalyticsPage = async (req, res) => { const cid = parseInt(req.params.category_id, 10); if (Number.isNaN(cid)) return Helpers.notAllowed(req, res); const category = await Categories.getCategoryData(cid); const { from, to } = getTimestamps(req.query.from, req.query.to); return res.render('community/analytics', { category, filters: { from, to, } }); };
This is the script (not all obviously) that's not being found and the cause of an error being thrown:
'use strict'; define('forum/community/analytics', ['api', 'components'], (api, components) => { const Analytics = { category: ajaxify.data.category, }; Analytics.init = () => { }; return Analytics; });
There are some functions in there that are not relevant, since the script doesn't even load. I just wanted to show how I defined it.
-
Unable to load template@pitaj I also have this issue in another plugin, but then it was only in the admin panel so I didn't put any effort into fixing it. This is on the forum itself, which is why I would like to sort it out.
-
Unable to load template@pitaj Yep.
Unable to load template: community/analytics nodebb.min.js:25493:12
and
Uncaught Error: Script error for "/assets/templates/community/analytics.js" https://requirejs.org/docs/errors.html#scripterror
These actually come up twice in one navigation.
I have tried rebuild/restart and clear cache.
-
Unable to load templateI have a number of custom templates in my plugin and for some reason browsing to them can sometimes cause issues. In Chrome it looks like it works fine, but Firefox seems to have issues.
It seems to originate from ajaxify.loadTemplate.
The template has a script attached to it via plugin.json as such:
"static/lib/communityAnalytics.js",
.The script itself is defined as follows
define('forum/community/analytics',
...Clicking on a link that takes you to that template/page works fine in Chrome, but fails in Firefox. Browsing directly to that page works in both browsers.
Any ideas?