Unsolved Pass parameters from one custom page to another

  • Hi All,

    I have created two custom pages. Everything works fine (both render properly and may be accessed).

    I wish to force page change from the first page to the second page (lets say upon button press handled by the first page js), and pass several parameters to the second page's js code.

    The second part of the question (passing data from the server side to the second page upon launch is simple: render('client/plugins/mycoolpage', mycoolparams);.

    I can't figure out the first part. Is there a function like:
    ajaxify.go('mycoolpage', mycoolparams) that will pass the parameters from the client to the render function above?

    Apology in advance for my ignorance. I am still learning nodebb.

    Thank you!

  • Community Rep

    One option, if you listen to action:ajaxify.dataLoaded, any changes to the data parameter are passed to the template render. For example, running this script below will change the first category to TEST

    let myNewCategory = 'TEST'
    $(window).one('action:ajaxify.dataLoaded', (e, params) => {
      if (params.data && params.data.categories) params.data.categories[0].name = myNewCategory

  • Thank you @yariplus .

    Not sure I understand, my apology.
    I wanted to store a parameter using the first page's js, and then force page change to the second page. Then have the second page's js code access said parameter.

    To that end, in your example, do I set

    • let myNewCategory = 'TEST'
    • ajaxify.go('categories')

    In the first page's js code, and:

    $(window).one('action:ajaxify.dataLoaded', (e, params) => {
    if (params.data && params.data.categories) params.data.categories[0].name = myNewCategory

    On the second page js code?

    I believe myNewCategory will be deleted on the page change (I tried that...). Again, apology for my ignorance.


  • NodeBB Admin

    Can't you just pass them as query params? On page 1 when a button is clicked do this


    On the second page client side you can read those params with

    var data = utils.params();
  • Community Rep

    @jjsagan No, everything would go on the first page. The second page's js would just read ajaxify.data.yourvariable

    I'm assuming you want to both render the variables in the second page's template, and use them in the second page's JS. If you just want to read them with JS, passing them in the url as baris says above is the easier option.

  • Thank you so much @baris and @yariplus - will give both options a try ­čśë

Suggested Topics

| | | |