How to post code on the forum. For absolute beginners.
I’m going to walk you through this. Why? Well, someone always helped me when I was new.
What better way to repay them? By helping others, that’s how.
At some point . . .
You’re going to be asked to post some of your code so that it can be looked at by
the people here on the forum. It helps them to help you.
Some of the reasons.
-
MagicMirror is telling you to create a config.js file, but you already did.
-
You added a module and now MagicMirror won’t load.
-
One of your modules just says “Loading…” on your mirror, but never does.
-
You get a black, or white, or blank screen on your mirror.
-
You get a syntax error reported in your terminal or console
The wrong way
If you just copy and paste your code into a topic on the forum, the result will look
something like this. Not too easy to look at, right? It loses its formatting.
Worse than that
If someone copies the code that you posted (the wrong way) there is an anomaly that often occurs. Some characters will be changed when pasted, causing the code to fail, and leaving you wondering why because you might not notice what characters were
changed. The most common unwanted changes concern quotes '
, double quotes "
and the comma ,
. Can you say, “Syntax error?”
The right way
-
The secret is . . . the “back-tick”.
-
If you enter one back-tick at the beginning of a word or words and one back-tick at the end of a word or words, you get “inline code” for that word or words.
Try it in a post. It should look like this
. Or, it can look like this
.
You’ll like this
-
Now we want to post a portion (or all) of our config.js
file (or any code) in the forum so that it can be viewed easily (and properly) by the people trying to help us.
-
You use three
back-ticks before the code AND three
back-ticks after the code. That is how you “fence” blocks of code. You will love the result!
Remember that code posted above?
- Well, this is how it looks when you “fence” it in with three back-ticks, before
AND
after the code. Tell me you don’t like this better? ;)
{
module: 'MMM - PrayerTime',
position: 'top_left',
config: {
apiVersion: '1.0',
lat: 12.089796,
lon: -56.807734,
timezone: 'EST',
method: 5,
playAdzan: ['fajr', 'dhuhr', 'asr’, 'maghrib', 'isha'],
notDisplayed: ['midnight', 'sunset'],
useUpdateInterval: true,
updateInterval: 86400 * 1000,
animationSpeed: 2.5 * 1000,
language: "en",
showAdzanAlert: true,
alertTimer: 15000
}
},
Is it a big deal?
-
No, it’s not, but for the sake of conformity we should all post code this way. You’ll like it better (because it looks nicer) and the people reading it will like it better (because it looks better) and we’ll all be one happy forum family.
-
And besides, it’s the way we’re supposed to be doing it. Climb aboard!
So, where is the back-tick key on my keyboard?
- On U.S. QUERTY keyboards it’s to the left of the 1 key (not the Numeric keys)
But I don’t use a U.S. QWERTY keyboard!
An even easier way.
-
Why did I put you through all that? I don’t know. I had to learn it that way so that’s how I teach it.
-
Just do this and forget everything I said above! Simply clicking the icon indicated by the red arrow will place the correct back-ticks in the correct place, with a highlighted //your code here
showing you where to paste your code.
Peace! :)