HELP | Oink! Oink! Grunt! Grunt! Where oh where have I gone wrong!

Re: HELP | Oink! Oink! Grunt! Grunt! Where oh where have I gone wrong!

by Mary Evans -
Number of replies: 2
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Gareth,

What is confounding me the most is that whatever I do it just isn't doing anything other than giving me errors.

I like the video and your explaination of whatyou are doing makes sense, I have not tried the method you used in that video yet, as I have been messing with the JS Modules stuff. I'm still not sure where this is supposed to go either...I need examples and can't find any!

<?php $PAGE->requires->js_call_amd($modulename, $functionname, $params); ?>

I am presuming that if I do something like this in the layout page it should work...

 <?php
    $modulename = 'theme_graphite/helloworld';
    $functionname = 'makeitBlue'; // I am presuming this is a function! LOL
    $params = '';
    $PAGE->requires->js_call_amd($modulename, $functionname, $params); ?>

It's oh so new to me and it is utterly frustraiting becasue I feel like I am going round in circles.

Cheers

Mary

In reply to Mary Evans

Re: HELP | Oink! Oink! Grunt! Grunt! Where oh where have I gone wrong!

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Mary,

Oh, you don't need the 'page requires' bit, that's for dynamic loading of modules (the next step and the docs was wrong with $OUTPUT so I've corrected that).

Ok, after using 'grunt' to make the 'amd/build' folder from 'amd/src' then you use a bit of JS in the theme to load it in an olderish sort of way: https://github.com/moodle/moodle/blob/master/theme/bootstrapbase/config.php#L157-L159 and https://github.com/moodle/moodle/blob/master/theme/bootstrapbase/javascript/moodlebootstrap.js - I learnt most of what I needed to learn from there and the documentation pages as referenced by the tracker by Damyon before they became live.  So in Shoelace this translates into (I decided to trim Bootstrap down, so no parent JS): https://github.com/gjb2048/moodle-theme_shoelace/blob/master/config.php#L56-L60 and https://github.com/gjb2048/moodle-theme_shoelace/blob/master/config.php#L56-L60 and https://github.com/gjb2048/moodle-theme_shoelace/blob/master/javascript/shoelace.js which loads the AMD modules from: https://github.com/gjb2048/moodle-theme_shoelace/tree/master/amd/build and the source: https://github.com/gjb2048/moodle-theme_shoelace/tree/master/amd/src

That should be all you need to get started again, cheers,

Gareth

In reply to Gareth J Barnard

Re: HELP | Oink! Oink! Grunt! Grunt! Where oh where have I gone wrong!

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Ah...but I want to learn about Javascript Modules and how they are loaded!

The fact that you can make them and add them to the theme/themename/amd/src directory means that they have to be compiled using 'grunt' so that the file is rebuilt as a minified file and stored in theme/themename/amd/build. And it this process that I am stuck with. Methinks the pigsty needs cleaning! LOL

Still...I am learning more. The code looks easier to read now and so I am not in awe of it as I first was.

There are lots of folks out there that are having same problem with that 'error message', and most solutions seems to point to coding ERRORS so perhaps Andrew needs to rethnk some of the code in Gruntfile.js as it is throwing an error saying that 'default' task is not defined and yet it is...so someone or something is wrong!

Thanks for the links and info. And yes I saw that you had amended the Moodle doc too. I corrected some "granma" in it the same day or the day before you.

Cheers and many thanks.

Mary