Picture of Dan Jonsson
miniTitle?
by Dan Jonsson - Monday, 11 January 2016, 1:03 PM
 

I want to fetch the data in miniTitle to a javascript file I trigger from the theme.

I have adjusted the vanilla.js file and I want to add the {{{miniTitle}}} which is set in the contentObject Json.

How is this done?

 

Danne/

Picture of Tom Taylor
Re: miniTitle?
by Tom Taylor - Monday, 11 January 2016, 2:28 PM
 

Hi Danne,

Depending on where you want your mini-title to show up, you'll probably want to have a look in the page.hbs template file.

Picture of Dan Jonsson
Re: miniTitle?
by Dan Jonsson - Monday, 11 January 2016, 2:43 PM
 

My problem is that I cant get the miniTitle (Chapter 1-2-3-4) info into a variable in a theme vanilla.js.

If I create a var in the theme js file it dosen´t recognizie the info in {{{miniTitle}}}.

Somewere I need a reference to the contentObject.json file into the javascript file!

 

D

Picture of Tom Taylor
Re: miniTitle?
by Tom Taylor - Monday, 11 January 2016, 3:50 PM
 

The triple brackets is a Handlebars thing, so won't do anything in plain JS. You can access any model information using dot notation though (e.g. model.miniTitle).

What is it that you're trying to do?

Picture of Dan Jonsson
Re: miniTitle?
by Dan Jonsson - Monday, 11 January 2016, 3:52 PM
 

Just adding a leftside menu to all pages.

I´ll try your suggestion!

D

Picture of Tom Taylor
Re: miniTitle?
by Tom Taylor - Monday, 11 January 2016, 4:06 PM
 

You can listen to various events to get hold of the model information you want. The pageView events are probably what you're looking for.

e.g.

Adapt.on("pageView:postRender", function(view) {

   // do things with the view.model data

});

Picture of Tom Taylor
Re: miniTitle?
by Tom Taylor - Monday, 11 January 2016, 4:07 PM
 

See this page for some help with the core events: https://github.com/adaptlearning/adapt_framework/wiki/Core-Events

Picture of Dan Jonsson
Re: miniTitle?
by Dan Jonsson - Monday, 11 January 2016, 6:50 PM
 

I got this function to work with:

 

Adapt.on('pageView:ready', function(view) {$(".sub_menu").empty();

titel = view.model.title;

$(".sub_menu").append("<div class=\"page sidebar_title\"><strong><h4>"+titel+"</h4></strong></div>");

}

 

I have shortened a little!

But I get undefined for the titel variable!

 

D

Picture of Dan Jonsson
Re: miniTitle?
by Dan Jonsson - Tuesday, 12 January 2016, 7:50 AM
 

Somewhere I read that the title needs an attribute.

How is the syntax for that?

 

D

Picture of Dan Jonsson
Re: miniTitle?
by Dan Jonsson - Tuesday, 12 January 2016, 8:43 AM
 

Thanks for your help!

This is how I got the title info:

var titel = view.model.get('title');

 

You made me a happy man!

D