Moodle for mobile

Getting data into templates for remote add-ons in 3.5

 
Picture of Mark Johnson
Getting data into templates for remote add-ons in 3.5
Core developersParticularly helpful MoodlersPlugin developers

I'm trying to write a remote add-on that uses the CoreCourseFormatDelegate.

So far, when I click on a course using our course format, it renders the template I'm providing instead of the default one, which is great.

I'm trying to avoid reinventing the wheel as our course format will have certain things in common with the default one (such as wanting to list all the modules within a section), so I'd like to copy some parts of the default template.  However, I'm coming unstuck when I try to do something like this:

<ng-container *ngFor="let section of sections">
    <ng-container *ngTemplateOutlet="sectionTemplate; context: {section: section}"></ng-container>
</ng-container>

If I understand correctly, the default template gets variables like the "sections" array from the format component.  Is it possible for me to pass that data from my remote add-on code, or do I have to do things like this using mustache templates rather than re-using the angular code?  I've tried passing an array of sections through CONTENT_OTHERDATA, but that only accepts scalar values and not arrays.

 
Average of ratings: -
Picture of Mark Johnson
Re: Getting data into templates for remote add-ons in 3.5
Core developersParticularly helpful MoodlersPlugin developers

Following a discussion in the dev chat, it appears that mustache is the way to go for now.

 
Average of ratings: -
Picture of Dani Palou
Re: Getting data into templates for remote add-ons in 3.5
Core developersMoodle HQParticularly helpful MoodlersPlugin developers

Hi Mark,

regarding returning arrays/objects in otherdata, we integrated a fix yesterday to allow returning them as JSON strings. The app will parse the JSON strings to convert them back to array or object.

Kind regards,

Dani

 
Average of ratings: -