• RE: Template helpers not working in in NodeBB v2

    @baris This worked like a charm. Thank you!

    posted in Plugin Development
  • RE: 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.

    posted in Plugin Development
  • Unable to override scripts

    Migrating 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
    • email

    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?

    posted in Plugin Development
  • RE: Template helpers not working in in NodeBB v2

    I get the following error client side:

    Uncaught TypeError: can't access property "registerHelper", Benchpress is undefined

    posted in Plugin Development
  • Template helpers not working in in NodeBB v2

    I'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.

    posted in Plugin Development
  • RE: 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

    1. Input username and password.
    2. Click register
    3. Fill in optional information

    Require email

    1. Input username, email and password
    2. Click register
    3. 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?

    posted in NodeBB Development
  • RE: 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.

    posted in NodeBB Development
  • 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.

    posted in NodeBB Development
  • RE: Test fail for missing translation key

    @julian Okay, I'll do that. Thanks!

    posted in NodeBB Development
  • RE: Test fail for missing translation key

    Okay 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?

    posted in NodeBB Development