template.js to benchpress issue.

Technical Support
  • I have an older plugin I'm trying to update after another developer, however, I'm confused by the change of engine.

    The template.js front-end code is:

          var html = templates.parse(template, {
            item       : item,
            isEdit     : true,
            categories : categories,
            SETTINGS   : ajaxify.data.SETTINGS,
          });
    

    I must be missing something, I really cannot see why it doesn't work with benchpress.

  • What is the value of template? You can't get the rendered HTML directly like that, you have to pass a callback as the last parameter.

    What you should be doing is using

    require(['benchpress'], function (benchpress) {
      benchpress.parse(template, data, function (html) {
        // do whatever
      });
    });
    
  • template.js was only used in two places and I still have a hard time figuring out how he's using template.js

    
      function handlerClickCard_btnEdit(e) {
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();
    
        var uid = $(this).attr('data-item-uid');
    
        if (!uid) return undefined;
    
        var item = ajaxify.data.list.find(function(itm) {
          return itm && itm.uid === uid
        });
    
        ajaxify.loadTemplate(self.config().templates.modalEditAlbum, function(template) {
          var categories = ajaxify.data.categories;
    
          // set selected option in selectbox
          if (item.category && item.category.cid) {
            categories.forEach(function(itm) {
              if (itm && itm.cid === item.category.cid) itm.selected = true;
            });
          }
    
          var html = templates.parse(template, {
            item       : item,
            isEdit     : true,
            categories : categories,
            SETTINGS   : ajaxify.data.SETTINGS,
          });
    
          bootbox.dialog({
            title   : '[[gallery:placeholder.edit]]' + ' "' + item.name + '"',
            message : html,
          });
        });
      }
    
      function handlerClick_btnNewGallery() {
        ajaxify.loadTemplate(self.config().templates.modalEditAlbum, function(template) {
          var categories = ajaxify.data.categories;
    
          console.log(template);
          var html = templates.parse(template, {
            item: {
              isPublic: false,
            },
            isNew      : true,
            categories : categories,
            SETTINGS   : ajaxify.data.SETTINGS,
          });
    
          bootbox.dialog({
            title   : '[[gallery:modal.title.new_gallery]]',
            message : html,
          });
        });
      }
  • @tmikaeld ok so instead of

    ajaxify.loadTemplate(templateName, function (template) {
      // before stuff
      var html = templates.parse(template, data);
      // after stuff
    });
    

    You should just do

    // before stuff
    benchpress.parse(templateName, data, function (html) {
      // after stuff
    });
    
  • What he's doing is super weird, he's loading in the template manually and then parsing it with templatesjs. That kind of flow is no longer supported, so you have to use the (arguably easier) form I suggested.

  • @PitaJ Thanks, I'll test it first thing tomorrow 🙂

  • @PitaJ

    Is benchpress not loaded globally?

    I get "benchpress is not defined", so i guess i need to require it, but do i have to do this in a wrapping function or can i use:

    var benchpress = require(['benchpress']);
    

    UPDATE:

    When i tried with var benchpress = require(['benchpress']); I get benchpress.parse is not a function

  • This is how i rewrote the functions by the way.

    var benchpress = require(['benchpress']);
    
      function handlerClickCard_btnEdit(e) {
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();
    
        var uid = $(this).attr('data-item-uid');
    
        if (!uid) return undefined;
    
        var item = ajaxify.data.list.find(function(itm) {
          return itm && itm.uid === uid
        });
    
          var categories = ajaxify.data.categories;
    
          // set selected option in selectbox
          if (item.category && item.category.cid) {
            categories.forEach(function(itm) {
              if (itm && itm.cid === item.category.cid) itm.selected = true;
            });
          }
    
          benchpress.parse(self.config().templates.modalEditAlbum, {
            item       : item,
            isEdit     : true,
            categories : categories,
            SETTINGS   : ajaxify.data.SETTINGS,
          }, function (html) {
            bootbox.dialog({
              title   : '[[gallery:placeholder.edit]]' + ' "' + item.name + '"',
              message : html,
            });
          });
    
      }
    
    
    
      function handlerClick_btnNewGallery() {
    		
        var categories = ajaxify.data.categories;
    
    		benchpress.parse(self.config().templates.modalEditAlbum, {
          item: {
            isPublic: false,
          },
          isNew      : true,
          categories : categories,
          SETTINGS   : ajaxify.data.SETTINGS,
          }, function (html) {
              bootbox.dialog({
                title   : '[[gallery:placeholder.edit]]' + ' "' + item.name + '"',
                message : html,
              });
            });
    
      }
    

    It this what you had in mind @PitaJ ?

  • require uses a callback.

    require(['benchpress'], function (benchpress) {
      // code that uses benchpress
    });
    
  • @yariplus Work! Thanks 🐶


Suggested Topics


  • Values to add to email templates

    Unsolved Technical Support
    0 Votes
    2 Posts
    116 Views

    @mattdjuk You can do a search for the string emailer.send( in src/ to see every invocation of the emailer.

    From the first argument passed in, you can see which template it attempts to use, and the third argument shows the template data passed in.

    e.g.

    await emailer.send('notification', uid, { path: notification.path, notification_url: notification.path.startsWith('http') ? notification.path : nconf.get('url') + notification.path, subject: utils.stripHTMLTags(notification.subject || '[[notifications:new_notification]]'), intro: utils.stripHTMLTags(notification.bodyShort), body: body, notification: notification, showUnsubscribe: true, })
  • 0 Votes
    6 Posts
    1k Views

    I also run into the problem. Whenever I want to save my customized CSS or Header :

    NodeBB encountered a problem saving changes

    By the suggestion above, I modify it to message: err.message, then it becomes:

    Changes Not Saved: unrecognized input

    What am I supposed to do? Below is my CSS:

    body { font-family: "Times New Roman"; } <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script>

    Header:

    <script type="text/x-mathjax-config"> MathJax.Hub.Config({ extensions: ["tex2jax.js"], tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }, TeX: {equationNumbers: { autoNumber: "AMS" } } }); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>

    BUILD log:

    root@iZ94134cujlZ:/nodebb# ./nodebb stop Stopping NodeBB. Goodbye! root@iZ94134cujlZ:/nodebb# ./nodebb build started 2018-02-26T03:00:31.355Z [21693] - info: [build] Building in parallel mode 2018-02-26T03:00:31.358Z [21693] - info: [build] plugin static dirs build started 2018-02-26T03:00:31.363Z [21693] - info: [build] requirejs modules build started 2018-02-26T03:00:31.365Z [21693] - info: [build] client js bundle build started 2018-02-26T03:00:31.367Z [21693] - info: [build] admin js bundle build started 2018-02-26T03:00:31.367Z [21693] - info: [build] client side styles build started 2018-02-26T03:00:31.368Z [21693] - info: [build] admin control panel styles build started 2018-02-26T03:00:31.370Z [21693] - info: [build] templates build started 2018-02-26T03:00:31.371Z [21693] - info: [build] languages build started 2018-02-26T03:00:31.372Z [21693] - info: [build] sounds build started 2018-02-26T03:00:40.698Z [21693] - info: [build] client js bundle build completed in 9.334sec 2018-02-26T03:00:40.698Z [21693] - info: [build] admin js bundle build completed in 9.331sec 2018-02-26T03:00:40.869Z [21693] - info: [build] sounds build completed in 9.497sec 2018-02-26T03:00:41.498Z [21693] - info: [build] plugin static dirs build completed in 10.14sec Witout `from` option PostCSS could generate wrong source map or do not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning 2018-02-26T03:00:54.973Z [21693] - info: [build] client side styles build completed in 23.606sec 2018-02-26T03:00:55.041Z [21693] - info: [build] admin control panel styles build completed in 23.673sec 2018-02-26T03:00:55.075Z [21693] - info: [build] requirejs modules build completed in 23.713sec 2018-02-26T03:01:00.042Z [21693] - info: [build] languages build completed in 28.671sec 2018-02-26T03:01:00.051Z [21693] - info: [build] templates build completed in 28.681sec 2018-02-26T03:01:00.053Z [21693] - info: [build] Asset compilation successful. Completed in 28.695sec. root@iZ94134cujlZ:/nodebb# ./nodebb start Starting NodeBB "./nodebb stop" to stop the NodeBB server "./nodebb log" to view server output "./nodebb help" for more commands
  • 0 Votes
    11 Posts
    4k Views

    @julian thanks that's good to know.
    I'll do as @pichalite recommended and fork the theme then.
    Thanks!

  • 0 Votes
    4 Posts
    3k Views

    Also /src/views/, for ACP templates

  • 0 Votes
    6 Posts
    4k Views

    @psychobunny nice, It's very helpful.