TNEW javascript loader, anyone?

Hi folks! I'm cross-posting this between the TNEW and Web forums because I think it's heavy on the custom programming side of things.

I am curious to know if anyone out there using TNEW in a highly customized manner has built any tools to enable themselves to more easily inject JavaScript snippets onto specified TNEW pages. My goal is to get this code out of system tables and content types, and into source control.

What I envision is a script file included in the TNEW template that contains blocks of code to be run on certain TNEW pages, as well as some kind of "loader" tool that identifies the TNEW page we are on and then runs the appropriate blocks on it. Part of the strucure of each block would be some kind of TNEW page selector that tells the loader which single or multiple pages it should be run on.

It occurs to me that this kind of tool might be very broadly useful to lots of different organizations, so I wanted to see if anyone has something they'd be willing to share (or would want to collaborate!) before starting on my own.

Parents
  • Hey Nick! I made something like this for us but it might not be as awesome and sophisticated as you might be looking for. :) 

    We're on WordPress and in our header I added some PHP that detects if we're on the TNEW template. If so, then I link to a custom javascript file that we host and add a class to identify what page we're on such as "tnew-page-single-SYOS" to the body element.  

    Then to make the magic happen, in that custom-tnew.js I have some code to detect that body class and do whatever I want.  



    [edited by: Josh TerAvest at 9:43 PM (GMT -6) on 13 Nov 2015]
  • Thanks Josh! I hadn't thought of using body classes as a kind of intermediate step, but that strikes me as a very wordpress-y way of doing things!

    Is the part of your code where you identify what TNEW page you're on and assign classes something you're willing and able to share? Interested in seeing some examples of methodology and level of detail.

Reply
  • Thanks Josh! I hadn't thought of using body classes as a kind of intermediate step, but that strikes me as a very wordpress-y way of doing things!

    Is the part of your code where you identify what TNEW page you're on and assign classes something you're willing and able to share? Interested in seeing some examples of methodology and level of detail.

Children