Unexpanded tokens in topics list parsed template output. No errors

Solved NodeBB Plugins
  • I have an object that has an array of topics

    obj = {

    The topics in this object are sorted in a desired order.
    If I dynamically load a template (on the client side) and then
    try to use it to render this list using

    ajaxify.loadTemplate('partials/topics_list', function(temp) {
        var html = templates.parse(temp, obj )

    I get html that is exactly what I want but also has things like [[global:posts]]
    and [[category:no_replies]]. I'm getting the feeling that those were supposed
    to be expanded by the parser.

    Is partials/topics_list expecting obj to have more things other than the topics: []
    and failing (silently?) because of that? Is there a second pass that needs to be invoked
    after templates.parse ?

    Goals: I rolled up a custom list of topics which I'd like to display on the frontend

  • You just need to translate the output as well. Check out the method app.parseAndTranslate

  • @baris said in Unexpanded tokens in topics list parsed template output. No errors:

    Check out the method app.parseAndTranslate

    Doesn't look like it can work as a drop in replacement for templates.parse

    Could you point me to the documentation/Unminified Source code for this function? How do I use it?

    Edit: Managed to get the unminified source by doing ./nodebb dev (was doing NODE_ENV=development node ./app.js before

  • Got it.

    Final code looks like this

    app.parseAndTranslate('partials/topics_list', obj, function(jqarr){
        var node = document.querySelector('.topic-list')
        node.innerHTML = jqarr.html()
  • @Qwertyzw in the future, you can use the Github search to find the source code for different apis.

Suggested Topics