1

Hokay, this is a big one. Thanks in advance for anyone that has a look:

I’m trying to get this widget working on a Craft site.

The install documentation is pretty simple, I've hosted it here: http://brycekirk.com/documentation/

I've also installed Business Logic. Within that plugin, I've created a folder called vendor and and moved the psmw folder into it.

I've then initialized it in BusinessLogicPlugin.php:

public function init() {
    require_once 'vendor/psmw/init.php';
}

and added into /variables/BusinessLogicVariable.php, I've added the path to the shortcode functions, and a test one:

public function shortcode($optional = null)
{
    require_once(CRAFT_PLUGINS_PATH.'businesslogic/vendor/psmw/shortcode.php');
    shortcode(['type' => 'spark', 'symbol' => 'AAPL', 'template' => 'line', 'color' => 'blue']);
}

And then called it in my template with {{ craft.businessLogic.shortcode }}. It's generating HTML and JS, but not displaying the ticker, and I'm getting a jQuery is not defined error.

I'm sure there's something wrong with the logic behind how I'm loading in the plugin and its assets, I just can't figure out what it is. Any gesture in the right direction would be much appreciated! I can provide more info if needed.

1

Sounds like you haven't loaded jQuery on that page. You'll need to make sure that jQuery is loaded before your {{ craft.businessLogic.shortcode }} tag.

| improve this answer | |
  • Loading my version of jQuery (3.3.1) in the head doesn't erase the error, but loading the version in the documentation (2.0.3) does. However, there's no change, the plugin still doesn't work. – Bryce Jan 26 '18 at 17:27
  • Maybe you could explain us what does not work? Do you receive a new error? Is there nothing at all in your console? Maybe there is a red entry in your network tab? – Robin Schambach Jan 26 '18 at 20:30
1

I'm not sure if this will help anyone in the future, but I was able to get it working. Basically, I needed to have the plugin folder psmw both in plugins/businesslogic/vendor and at the root of my project. The PHP was executed within the plugin, while the CSS and JS was referenced from the root, since you can't point to assets within the plugin folder from a Craft template. May not be the sexiest method, but it works.

| improve this answer | |
  • Of course you can craftcms.com/docs/plugins/resources includeJsResource('pluginName/path/to/file.js') will point to a plugins js file. So you just need to move the files to your Ressource folder. There are also ways to reference them in your plugins main folder but that requires a little bit more knowledge – Robin Schambach Jan 26 '18 at 22:49
  • Thanks, didn't know about that, I'll have a look! – Bryce Jan 28 '18 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.