How can a theme modify the behaviour of NodeJS?

Moved Technical Support
  • Hi.

    In my theme, I want to modify the breadcrumb on pages like the category page and the topic page so that the top-level category is not a link.
    For example in the following breadcrumb, I want Home, B and C do be links, but A and D to be simple text:

    Home > A > B > C > D

    My problem is that the breadcrumb.tpl doesn't "receive" the required data to be able to see which breadcrumb entry is what in the loop.

    I want to modify (replace) the helpers#buildCategoryBreadcrumbs function with my theme.
    The idea is too add the category's parent CID to each breadcrumb entry, so that I could check if it exists in the template to see if it's a top-level category.

    How could I do that?

    • I'm not sure if it's a good thing if it's in NodeBB itself, so I don't know if I should make a PR for it
    • I don't know if a theme is able to replace js files like that
    • I don't know if a plugin (as themes are plugins afaik) can do that either


    EDIT: For now, I've got this:

    • breadcrumb.tpl in theme:
    <ol class="breadcrumb">
    	<!-- BEGIN breadcrumbs -->
    	<li itemscope="itemscope" itemtype="" <!-- IF @last -->class="active"<!-- ENDIF @last -->>
    		<!-- IF [email protected] --><!-- IF !breadcrumbs.isTopLevelCategory --><a href="{breadcrumbs.url}" itemprop="url"><!-- ENDIF !breadcrumbs.isTopLevelCategory --><!-- ENDIF [email protected] -->
    			<span itemprop="title">
    				<!-- IF @last -->
    				<!-- IF !feeds:disableRSS -->
    				<!-- IF rssFeedUrl --><a target="_blank" href="{rssFeedUrl}"><i class="fa fa-rss-square"></i></a><!-- ENDIF rssFeedUrl --><!-- ENDIF !feeds:disableRSS -->
    				<!-- ENDIF @last -->
    		<!-- IF [email protected] --><!-- IF !breadcrumbs.isTopLevelCategory --></a><!-- ENDIF !breadcrumbs.isTopLevelCategory --><!-- ENDIF [email protected] -->
    	<!-- END breadcrumbs -->
    • helpers#buildCategoryBreadcrumbs in src/controllers/helpers.js
    helpers.buildCategoryBreadcrumbs = function(cid, callback) {
    	var breadcrumbs = [];
    	async.whilst(function() {
    		return parseInt(cid, 10);
    	}, function(next) {
    		categories.getCategoryFields(cid, ['name', 'slug', 'parentCid'], function(err, data) {
    			if (err) {
    				return next(err);
    				text: validator.escape(,
    				url: nconf.get('relative_path') + '/category/' + data.slug,
    				isTopLevelCategory: data.parentCid == 0 ? 1 : 0
    			cid = data.parentCid;
    	}, function(err) {
    		if (err) {
    			return callback(err);
    			text: '[[global:home]]',
    			url: nconf.get('relative_path') + '/'
    		callback(null, breadcrumbs);
  • Bumb, this single line of JS added is the onyl change I have to do to NodeBB's sources for my theme to work, would be nice if I could get rid of it!

  • @Ribesg Building the breadcrumbs for a topic page is different from the regular breadcrumbs because we need to climb up through the parents to find the path back to the index page.

    So perhaps we could just add hasParent to the breadcrumb data, and then you could use it in your template.

    Would that work for you?

  • @julian I think, yes, as this would have the same value than my own change.

  • Feel free to add a pull request for this if you haven't already 🙂

Suggested Topics