• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Unexpanded tokens in topics list parsed template output. No errors

Scheduled Pinned Locked Moved Solved NodeBB Plugins
5 Posts 3 Posters 1.8k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qwertyzw
    wrote on last edited by
    #1

    I have an object that has an array of topics

    obj = {
        topics:[
            topic1,
            topic2,
            topic3
        ]
    }
    

    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 )
        console.log(html)
    });
    

    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

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #2

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

    Q 1 Reply Last reply
    1
  • Q Offline
    Q Offline
    Qwertyzw
    replied to <baris> on last edited by Qwertyzw
    #3

    @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

    1 Reply Last reply
    0
  • Q Offline
    Q Offline
    Qwertyzw
    wrote on last edited by Qwertyzw
    #4

    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()
    })       
    
    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Qwertyzw on last edited by
    #5

    @Qwertyzw in the future, you can use the Github search to find the source code for different apis.

    1 Reply Last reply
    1

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development