• 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

template.js not executed

Scheduled Pinned Locked Moved Solved Technical Support
15 Posts 3 Posters 625 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.
  • B Offline
    B Offline
    Bejan
    wrote on last edited by Bejan
    #1

    Using this setup https://community.nodebb.org/topic/16017/theme-quickstart-template-created-is-found-no-404-but-not-rendered/6# . However, the javascript in the associated mynewtemplate.js file is not executed.

    Console shows no error and the mynewtemplate.js gets loaded as assets/src/client/mynewtemplate.js (visible in Sources).

    In plugin.js the config is ../client/mynewtemplate.js. The prefix ../ resolves the path to assets/src/client instead of assets/src/modules/client but what is the reasoning behind this?

    Also, I tried using pure JS instead of jQuery in mynewtemplate.js:

    document.getElementById('last-p').innerHTML = 'hello world';
    

    Still no joy. No "hello world" in <p> tag.

    1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    wrote on last edited by
    #2

    You really need to share all of the modifications you've made. Have you added the file to plugin.json?

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

    Keep in mind the mynewtemplate.js will be loaded if the template name is also mynewtemplate.tpl Once that page is rendered it will try to load the requirejs module forum/mynewtemplate

    B 1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to PitaJ on last edited by
    #4

    @pitaj

    {¬                                                                                                                                      
      "id": "nodebb-theme-my-forum",¬                                                                                                     
      "hooks": [¬                                                                                                                         
        { "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" },¬                                                                { "hook": "filter:config.get", "method": "getThemeConfig" },¬                                                                     
        { "hook": "static:app.load", "method": "init" },¬                                                                                 
        { "hook": "filter:admin.header.build", "method": "addAdminNavigation" },¬                                                         
        { "hook": "filter:topic.build", "method": "addUserToTopic" }¬                                                                     
      ],¬                                                                                                                                 
      "scripts": [¬                                                                                                                       
        "public/my-forum.js",¬                                                                                                            
        "public/modules/autohidingnavbar.js",¬                                                                                            
        "public/modules/quickreply.js"¬                                                                                                   
      ],¬                                                                                                                                 
      "staticDirs": {¬                                                                                                                    
        "static": "./static"¬                                                                                                             
      },¬                                                                                                                                 
      "modules": {¬                                                                                                                       
        "pulling.js": "node_modules/pulling/build/pulling-drawer.js",¬                                                                    
        "../client/mynewtemplate.js": "./static/lib/mynewtemplate.js"¬                                                                                                                                                                
      },¬                                                                                                                                 
      "acpScripts": [¬                                                                                                                    
        "public/admin.js"¬                                                                                                                
      ],¬                                                                                                                                 
      "languages": "languages"¬                                                                                                           
    }
    
    1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to <baris> on last edited by
    #5

    @baris said in template.js not executed:

    Keep in mind the mynewtemplate.js will be loaded if the template name is also mynewtemplate.tpl

    That is how I figured it would work. It seems not to be working (like this), though.

    Once that page is rendered it will try to load the requirejs module forum/mynewtemplate

    Do you mean, once mynewtemplate.tpl is rendered a file called mynewtemplate.js will be loaded by requirejs? I expected this to be working, something seems amiss though. Where should I start looking?

    Thank you,

    B 1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to Bejan on last edited by
    #6

    That's weird. The js file gets loaded and is present in the sources tab in dev console. It's just not executed in the rendered template. Executing the js code in the console manually yields the expected result in the rendered template, though.

    Any ideas how to get the js code executed?

    Thanks.

    1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    wrote on last edited by
    #7

    What are the contents of that file? Have you tried just mynewtemplate.js instead of ../client/mynewtemplate.js?

    B 2 Replies Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to PitaJ on last edited by
    #8

    @pitaj said in template.js not executed:

    What are the contents of that file?

    "use strict";
    define("mynewtemplate",function(){
    var t={};
    t.init=function(){$("#last-p").text("mynewtemplate.js got loaded!");};
    return t
    });
    //# sourceMappingURL=home.js.map
    

    Have you tried just mynewtemplate.js instead of ../client/mynewtemplate.js?

    You mean in the json file? I believe I tried that, too, once. Cannot remember the results. Will try again and report back.

    1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to PitaJ on last edited by
    #9

    @pitaj What would happen if you're using the custom pages plugin to create a route mynewtemplate and put widgets inside at the same time as creating a file templates/mynewtemplate.tpl and a corresponding mynewtemplate.js file?

    The custom pages template takes precedence it seems like. But even without the custom pages template, the mynewtemplate.js is not executed.

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

    Take a look at https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/static/lib/quickstart.js, that file is loaded when quickstart.tpl is rendered.

    B 1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to <baris> on last edited by
    #11

    @baris Thank you.

    Well, that is where I got the JS from in the first place. I renamed the files from quickstart.* and added those to the custom theme, then adapted plugin.json. That is where I am at right now. I seem to cannot get the JS rendering to work. Template is shown, the last-p inner HTML is not. I'm out of clues now.

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

    @bejan said in template.js not executed:

    define("mynewtemplate",function(){

    This seems wrong, it should be forum/mynewtemplate like it is in quickstart plugin.

    B 1 Reply Last reply
    1
  • B Bejan has marked this topic as solved on
  • B Offline
    B Offline
    Bejan
    replied to <baris> on last edited by
    #13

    @baris Your hint did it! ✌ Thank you!

    Next question: where does that forum string come from? Is it because of some internal thing in nodebb?

    Again, thank you! 🙂

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

    Yeah it is coming from https://github.com/NodeBB/NodeBB/blob/master/public/src/require-config.js#L8

    B 1 Reply Last reply
    0
  • B Offline
    B Offline
    Bejan
    replied to <baris> on last edited by
    #15

    @baris Dam.. there it is, where all those magic strings meet! 😉
    Thank you.

    1 Reply Last reply
    0

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