MODX Forum user
justinet pointed out that the
$modx->regClientScript() methods add
regClient...() methods, MODX adds
The type specification is harmless, but it's not correct in HTML5. If you validate your code (and it's a very good idea to do so), the validator will complain with something like this:
The value of this tip may be short-lived. By the time you read this, MODX may have been modified so that it no longer adds the type specification. The fix is quite simple, though, and doesn't require any modifications to the core code, so it will still work fine after the code is updated.
One of the reasons I love MODX is the forethought you see in its code. When I first saw the documentation on the
regClient...() methods for scripts, I thought I would have to remember whether or not I should include
tags myself or expect MODX to insert them. It turned out that I don't have to remember, though, because MODX looks at the code you're submitting and adds the script tags *only* if they're missing.
The solution, then, is to simply surround your code with
tags (without the type specification) and MODX will inject them without modification. The only drawback of this method is that if the code you're injecting with
regClient() references a
One solution is to rename the file extension to
In the next article, we'll look at a trick for selecting the language used by a MODX extra package.
Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)