<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Module shows no text.]]></title><description><![CDATA[<p dir="auto">Hi everybody! :upside-down_face:</p>
<p dir="auto">I tried to write a module for the first time. It was supposed to show the menu including the prices of the canteen at our university, but for some reason I don’t get an output. I tried to run the logic and a test module with „hello world“ and both worked. I attached to this message my code and I hope that someone can help me out with this issue.</p>
<p dir="auto">Here ist my code:</p>
<pre><code>Module.register("MMM-Test", {
  defaults: {},
  start: function () {
	this.count = 0
  	var timer = setInterval(()=&gt;{
    		this.updateDom()
    		this.count++
  		}, 30000) // 1000 = 1s
	},
  getDom: function() {
    var element = document.createElement("div")
  element.className = "myContent"
    var subElement = document.createElement('table');
    var tr = document.createElement('tr');
    var td1 = document.createElement('td');
    var td2 = document.createElement('td');
    var request = require('request');
    var text1;
    var text2;
    var heute = new Date().toISOString().substr(0,10);
    var cnt = 0;
 request({
    url: 'https://openmensa.org/api/v2/canteens/838/days/'+heute+'/meals',
    json: true
 }, function(error, response, body) {
        element.innerHTML = ('\nCAFETERIA EAH am ' +  heute.substring(8,10)+ '.'+heute.substring(5,7) +'.'+heute.substring(0,4)+':');
	if (body.length &lt; 1){
		text1 = document.createTextNode('Heute geschlossen!');
	}
	else {
	  while (body.length &gt; cnt) {
		text1 = document.createTextNode((body[cnt].name));
		text2 = document.createTextNode(body[cnt++].prices.employees.toFixed(2) +' €');
		}
	}
});
    td1.appendChild(text1);
    td2.appendChild(text2);
    tr.appendChild(td1);
    tr.appendChild(td2);
    subElement.appendChild(tr);
    subElement.id = "COUNT"
    element.appendChild(subElement)
return element
},
  notificationReceived: function() {},
  socketNotificationReceived: function() {},
})

</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/10932/module-shows-no-text</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 17:38:33 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/10932.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Aug 2019 14:53:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Module shows no text. on Fri, 16 Aug 2019 06:41:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a><br />
Yes, you’re right. it was just an example. Anyway, it can be done like this;</p>
<pre><code class="language-js">parseContent: function(text) {
    this.lastPatched = JSON.parse(text)
    this.updateDom()
},

getDom: function() {
    var dom = document.createElement("div")
    dom.id = "TEST"
    if (this.lastPatched) {
      ... // draw patched data...
    }
    return dom
}
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/60136</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/60136</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Fri, 16 Aug 2019 06:41:15 GMT</pubDate></item><item><title><![CDATA[Reply to Module shows no text. on Fri, 16 Aug 2019 03:50:33 GMT]]></title><description><![CDATA[<p dir="auto">@Sean doable, but sloppy. Supposed to call updatedDom(), and let mm handle the actual update.</p>
]]></description><link>https://forum.magicmirror.builders/post/60135</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/60135</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 16 Aug 2019 03:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to Module shows no text. on Thu, 15 Aug 2019 16:39:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/k-0" aria-label="Profile: k-0">@<bdi>k-0</bdi></a><br />
Try this;</p>
<pre><code class="language-js">Module.register("MMM-Test", {
  defaults: {},
  start: function () {
    this.count = 0
    this.timer = null
  },

  getContent: function() {
    var heute = new Date().toISOString().substr(0,10);
    var cnt = 0;
    var url = 'https://openmensa.org/api/v2/canteens/838/days/' + heute + '/meals'
    fetch(url, {mode:"cors"})
    .then((response) =&gt; {
      console.log("Response fetched.")
      return response.text();
    })
    .then((text) =&gt; {
      this.parseContent(text)
    })
    .catch((error) =&gt; {
      console.log('Error:', error)
    })

    this.timer = setTimeout(()=&gt;{
      this.getContent()
    }, 30000)
  },

  parseContent: function(text) {
    var dom = document.getElementById("TEST")
    dom.innerHTML = ""
    var data = JSON.parse(text)
    for (let i = 0; i &lt; data.length; i++) {
      var item = data[i]
      var elem = document.createElement("div")
      elem.innerHTML = `${item.category} - ${item.name}`
      dom.appendChild(elem)
    }
  },

  notificationReceived: function(noti, payload, sender) {
    if (noti == "DOM_OBJECTS_CREATED") {
      this.getContent()
    }
  },

  getDom: function() {
    var dom = document.createElement("div")
    dom.id = "TEST"
    return dom
  }
})

</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/60118</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/60118</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 15 Aug 2019 16:39:24 GMT</pubDate></item><item><title><![CDATA[Reply to Module shows no text. on Thu, 15 Aug 2019 11:09:12 GMT]]></title><description><![CDATA[<p dir="auto">Can you (or someone else) give me an example? I have no experience with async programming.<br />
I tried to solve this problem with     setTimeout(function() { <em>mycode</em> }, 6000) , but it doesn’t work.</p>
]]></description><link>https://forum.magicmirror.builders/post/60099</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/60099</guid><dc:creator><![CDATA[k-0]]></dc:creator><pubDate>Thu, 15 Aug 2019 11:09:12 GMT</pubDate></item><item><title><![CDATA[Reply to Module shows no text. on Fri, 09 Aug 2019 13:18:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/k-0" aria-label="Profile: k-0">@<bdi>k-0</bdi></a>  request is an async call, it will return immediately, but the callback function will not happen until a LONG time  after the getdom() function returns…</p>
<p dir="auto">you need to do this someplace else (on a timer maybe)…</p>
<p dir="auto">and when the request returns, then save the data and signal mm with this.updateDom() to indicate new data is ready for viewing… MM will then call your getDom() routine…</p>
]]></description><link>https://forum.magicmirror.builders/post/59926</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/59926</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 09 Aug 2019 13:18:18 GMT</pubDate></item></channel></rss>