Jump to content

Javascript in Processwire Admin tab


David Beesley
 Share

Recommended Posts

Hi All,

I am developing an admin tab for a site using Ben Byford's tutorial here -> https://webdesign.tutsplus.com/tutorials/extending-the-processwire-admin-using-custom-modules--cms-26863

So far so good, it's working and showing me some content.

The ultimate aim for this is to be an interface with an external API. So I am looking to develop it as a mini Vue.Js single page app.

I can inject the javascript for the app using the following code in my template

$config = wire('config');

$config->scripts->add($config->urls->templates . "scripts/app.js");

The javascript is currently just grabbing a div with the id "app" and inserting "Hello World".

'use strict';

var app = document.getElementById('app');
app.innerHTML = '<p>Hello World</p>';

The problem is, presumably because the JavaScript is injected into the HEAD. I'm not grabbing the element 'app',

app.js:4 Uncaught TypeError: Cannot set property 'innerHTML' of null

Can anyone suggest a better approach for adding JavaScript to the admin area?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...