[ckan-dev] Can we add a data-module into a template loaded from ajax_snippets

Qifeng.Bai at csiro.au Qifeng.Bai at csiro.au
Mon Jun 9 23:16:12 UTC 2014


Thanks for your answer. I solved it by putting a js module into an upper level div element, instead of putting it into the template.

Cheers

From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Vitor Baptista
Sent: Sunday, 8 June 2014 12:45 PM
To: CKAN Development Discussions
Subject: Re: [ckan-dev] Can we add a data-module into a template loaded from ajax_snippets

Hi Qifeng,

The modules are initialized at https://github.com/ckan/ckan/blob/master/ckan/public/base/javascript/main.js#L36 , which happens as soon as main.js is loaded on the page. Any module defined after that won't be initialized.

If you really need it, you could call ckan.initialize() after loading any other modules on your page, but I'd rather avoid it. I'm not sure what consequences it'll have.

Cheers,

2014-06-04 2:49 GMT-03:00 <Qifeng.Bai at csiro.au<mailto:Qifeng.Bai at csiro.au>>:
Hi, there

I have a javascript data-module which reads a template file in ajax_snippets and show it on the page.  It works well.

In this template file, I try to call another data-module. It seems this data-module is not fired at all.

For example, I defined a template file called ‘test.html’ under ajax_snippets:
In test.html, I wrote “<div data-module=’init_test’></div>”

This module does nothing, just print out some info:
ckan.module(’init_test’, function ($, _) {
  return {
    initialize: function () {
      $.proxyAll(this, /_on/);
      Consol.log(‘I am inited’);
  },
………………

And then in an outside data-module, I called :

this.sandbox.client.getTemplate(test.html’, this._onReceiveTemplate);
……………………………………..

I found after the test.html was shown on the page, but there was no any console outputs.

Is that meant to be?

Cheers





[cid:image001.gif at 01CC55BF.85E7FEB0]

Qifeng Bai
Software Engineer
CSIRO Land and Water
Black Mountain, Canberra

Ph: +61-2-62465704<tel:%2B61-2-62465704>
Web: www.clw.csiro.au<http://www.clw.csiro.au>




_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org<mailto:ckan-dev at lists.okfn.org>
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev



--

Vítor Baptista

Developer  |  http://vitorbaptista.com | LinkedIn<http://www.linkedin.com/in/vitorbaptista> | @vitorbaptista<http://twitter.com/vitorbaptista>

The Open Knowledge Foundation<http://okfn.org>

Empowering through Open Knowledge

http://okfn.org/  |  @okfn<http://twitter.com/okfn>  |  OKF on Facebook<https://www.facebook.com/OKFNetwork>  |  Blog<http://blog.okfn.org/>  |  Newsletter<http://okfn.org/about/newsletter/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140609/24fb0114/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 2094 bytes
Desc: image001.gif
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140609/24fb0114/attachment-0003.gif>


More information about the ckan-dev mailing list