© NO. 1 FOR RASPBERRY PI
The essential monthly guide for coders & makers MINIAVSE\@S<0)s
www.linuxuser.co.uk
FIND ALL THE TUTORIAL
FILES YOU NEED ©
www.linuxuser.co.uk/tutorial-files
MOOcs
a Ow to
Ow ae Ne |
ew @ an
SIU EDP
RASPBERRY PI
VIDEO PLAYER
Add a touchscreen to your
Pi and make it play videos
DigitalEcition
GreatDigitalMagscm
ey
withtSULT val ast
RASPBERRY
id |
Keep your Pi safe with an
SOO CULO LT
www.sbeshop.co.uk call 0203 514.0914
At SB Components we strive to offer our customers the best prices for the best products.
Our product team works tirelessly to source top quality affordable components from around the world.
Dee ee LyWelcome
toissue 142 of Linux User & Developer
# RobZwetsloot sas srsps:eongnsrng
cargyantonegacamper
Sindutin rolonnghi tert
‘grdeyetdevessegerermnerts
‘ethatatpymachp, Reb
we} tesunactomnsvestnglantobuis
‘Tuspouny Pe ayeroap
Sahisanestoonstloby hero
‘St. anare steer
Richard Sm« started using computers ong,
‘rthsiontby ear Aawelas
‘wringtoreadngopen source
Magione elps rms setup
‘2nduse ponsouresoftware for
{hoirbusiness ped Overon page
DErNitehexpianshawtomanage
bis polecteusingLbveRan
Mihalis Tsoukalos ieaunixeytem
‘edminstetornthesgertsein
Programming. datbasesand
mathe. Ha haben ving nu
‘nce 1998 inte ue. Mra
Shee ushow wean uta
‘Sndadminatora epalebete
tsingthe comand tne and
‘sertngitrtace rush (page <2,
Jon Mastersica.inuxkemsthsckerwhohas
ben workingontinactor ame
"years, sine he frst attended
Your team of Linux experts...
unferatyat the ageof 3. Jon ves
incamordge, Massachusats,
‘snéwors forage onterpice
UUniavendor You canting
bullae kernel Column on pages
sesehie month
Gareth Halfacree sou ressentrowe
reporter andbringsusthelatest
‘evelopment tom allover the
‘pen sores wor startingon
page. Seepage ors biiant
. Fevtew ofthe new Cubstach
‘evignd for those who
‘utgronn the Cubicboard
[eC
Linux User
font-lel1g
Ce aA)
This issue
» Simplify project planning
» Start writing Bash scripts
» Code an RSS reader for Android
» Make a hand-held video player with Pi
Welcome to the latest edition of Linux User &
Developer, the UK and America’s favourite Linux
and open source maga:
Linuxusersare, fundamentally, a self-taught
bunch. And for every hour of format training received
bya Linuxdeveloper, countless more have been
spentin the tenacious pursuit of solutions to coding
problems. But one of the things that makes this all work is the
strength of the Linux community, continually communicating
and sharing knowledge, and this kind of dynamic interaction
is beginning to shake up the education establishment at
large. This month, following ed's move to make its acclaimed
Introduction to Linux course free and open, we take a lookat
the rise of Massive Open Online Courses (MO0Cs)
We also dive into the hugely anticipated Linux Mint 17 long-
term support release, Giana, tofind out whether Distrowatch’s
highest-ranking distro really does deliver the complete
package. With this being Cinnamon's first appearance in an
LTS release and Giana being the culmination of years’ worth of
effort, it’s one of the most exciting releases we've seen yet
There's another great tutorial line-up, too. This issue we
cover Drush, Revel and LibrePlan, touchscreens and servos
with the Pi, we start a new series on shell scripts and continue
our Android series with a look at networkingapps. Have fun,
Gavin Thomas, Deputy Editor
Get in touch with the team:
[email protected]
imagineshop-o.x
etd
Visit us online for more news, opinion, tutorials and reviews:
www.linuxuser.co.uk
Issue 14216 Linux Mint 17
Hands-on tour and in-depth review of the new LTS release
OpenSource
06 News
The bi
open:
14 Kernel Column
Thelatest onthe Linux
Kernelwith Jon Masters
79 Books
Some of thebest bookson
Linuxand open source
94 Letters
Your view
stories fromthe
eworld
on the magazine
he open source scene
Features
16 Linux Mint 17
Exergy nessa
26 Learn Linux for free
MOOCs and the rise of open
source education
50 Code apps for Android
ogee er Ana
Thismonth wecodeanRSS
reader to explore networking
88 Q&A
Your questions answered
Tutorials
30 Edkevideo in Kdenlive
2 to use this powerfulopen
tor tomake movies
32 Write useful shell scripts
part 1
jon your command line knowledge to
useful Bast
36 Simplify your project planning
with Librel
cron LibrePlan tomanage
42 pun Drupal sites with Drush
drminister a Drupal website fromthe
command tine
46 Generate webpage templates
with Go+
Se ea eiteidnakroqats
On your free disc
96 Cover disc TvE-BOOTINGDYD
ered’
foo
Reviews
ry
80 Cubietruck
Cantthe boosted spe
itsincreasedseling pric
82 Makeblock
WilithisArduino-powered
robotinvade theclassroon?
a
84 LXLE 14.04
Canthis lightweight
breathe newlfetocid POS?
Join us online for more Linux news, opinion and reviews www.linuxuser.co.uk
vivitinuxuser co.uk¢ oD PRO
YOUR HOSTING
COMPANY
WEB HOSTING FROM pee Rey DEDICATED SERVERS FROM
WEBDESIGNERMAG06 News | 12 Opinion | 94 Letters
OpenSources
HP unveils Linux-
powered ‘The Machine’
Cutting-edge project uses memristor and photonics technology
Howlett Packard has announced it intention
‘to ship the world's first commercial computer
‘based around iticon photonics and memristor
technologies within the next six years,
‘custom-built operating system
ye Linux kernel.
represent
would be used by the syst
for both working memory and
0-caled universal memory
he advantages
many, Performanc
HP's memristor technology, first postulatedin 1971, erases the distinction between working
memoryand storage
Aims to release The Machine
between 2017 and 2020
vwouldaiso drop, wth roneed to supply constant
ted that itis dedicating around
its research and development
axkernel This operating,
sed under an as yet 75 per
lisence, the company divs
13 the company’s
to The
reach fruition,
hnology being
traditional
semiconductor transistors with versions based
‘oncarben naiotube technelegy
is also said to includeNews
The latest in the Linux community
OPEN source I
Gan
KDE c details future plans
‘The KOE Project has summarised its future
direction developments, with Jos Poortulct
Posting a detailed breakdown to the projects
offical website,
Jos Poortlit detailed the development
direction, while also showing off new designs
HARDWARE
Nvidia partners for
64-bit ARM servers
Nvidia, once described as “the worst
company" by Linux founder Linus Torvalds
has announced a partnership with three
companies to produce 64-bit ARM-based
servorsrunning GNU/Linux
The company has joined
Crrascale, E4 Computer Engineering and
Eurotech | to produce rack-mountable
computing nodes based on Applied
Micro's X-Gene ARMs processors ~ nat
interestingly, Nvidia's own TograK1 ARM.
processor. These systems feature the
Linux port of the companys CUDA
application programming interfacs
(APO to allow processing to be
offloaded to bundled Tela K20
accelerator cards,
Based on the same technology a ite
graphics processors, the Tesla family feature
ro graphics output butinstead use thousands
Of stream processors and a lage quantity
of high-speed GODRS memory to speed up
hiehiy parallel applications.
Intl models areavaliableto purchase now
m Nvidia's 64-bit
‘ARM: based
servers wil
foatureits Tesla
accelerator
boards
Linux calendar
BU AUT Rd
DCT EST lulis
FeO Ma
ary
ee ed
ey
Pees
Panera tener ae
Rea
leaders, and to plan the future
cori
Pa
peso
18th - 20th August
See ea)
Oey
eet
USA
Pee nar ed
gust
Raa
Pet recor aes
re ae ec)
eee uy
Tre
eer icid
20th - 22nd Au;
ere ag
Reentry
ary
Penni
The annual
ere a
ihre eats
the Debian Perl Group,
3
2
is
iB
re
8
&
FrOsCon
ere
Esa essere teste
roy
rent
eee
fcr
ear
en)
ompreh
23rd - 24th AugustOpenSource voursourceoftinuxnewsand views
NAAN oe fees tn
Respondly goes free
for FOSS (Ue
expands vezi
Team communications service gives back
Respondly, the collaborative communications
platform designed to improve customer
relationship management, hs announced that
{open-source projects can ows upto.
delays in shipping the
See tT
enters
Respondly wants to improve user
‘communications in open-source projects
another Ope eee
HARDWARE.
Russian government looks to Linux
Homek Cortex®-AS7 MPCore
ARH Coreg” Mucor Dab an Trace
‘The Russian Ministry of Industry has
portedly announced plans to produce
1d processor, dubbed
ill be produced locally to
Baikal, which
ower’ GNU/Linux-based computers for
miconductor mana
ade: a juma to 28nm wil
itie reported, would be used to run a variant of take te to compete and cast a considerable
GNU/Linux aloredfor the local market. money to retook the fectones and its low-power designs are geting increasing
Tha papers souces suggest that the cit interest in the sever sector of late, and its
reasoning behind the moveisto reduce Russias While holding the majorty share ofthe mobile based li
facturing: at present, market, ARM ety absent from the and Io
desktop since the PC ofthe Nineties, pro
mTheaimisto moveto GNU/Linux-based
systems on a Homebrew Cortex-AS7 design
manufactur
ts of AMDandintl
the overwhelming majority ofthe gover
vivitinuxuser co.ukNews
The latest in the Linux cormmunity
OPEN SOURCE)
| FIREFOX J
Mozilla adopting
VR Technology
Firefox gets early Oculus Rift support
Mozila's Viadimir Vukidevié has revealed that 0 video support
he is leading a project atthe company to build
virtual reality technologies into the open-
Firefox's support for VRisplay devices will
be starting withthe Oculus Rift
support for VR display devi
BEE -
Node.js drops Needles Cree)
Doren oerer i
Contributor Agreements
Summer Special Offer m
|e
Still sticking MIT licence
‘The Nodeje project has announced that itis to do away with the
requirement for asigned Contributor Licence Agreement (CLA in order
‘to encourage external contribution. Butt
On Award Winning Hosting
improved
Goer
our legal Fast UK Web Servers
metodo so
Doe
eed
GC
SO Sed
pat the featur no a release u ‘The Only UK Web Host To Offer A
feedback heclaimed,"whchiswhy events ineNodeo vi Lifetime Money Back Guarantee!
save50IUOpenSource yoursourceoftinuxnewsand views
NAAN be tlhe le
[NEW RELEASE |
Red Hat Enterprise Linux 7 released
Anticipating the future and raising the bar, RHEL 7
caters for current and next-gen ne
Renae
Satellite 6 beta
Earlior last month, Red Hat announced the
1 maxiors
1 CucaoPs.
ployment, RHEL.7 deliver: burgeoning
end by enab
sapabilties, includ
virtual and:
The industry-standard SPECIbb2013
benchmark measures Java-based
application performance
Product plans and pricing for Red Hat
Enterprise Linux 7 canbe found at wmw.
redhat.com/wapps/store/eatalog.htmt
administrator
On top of that, the
Ethernet in
during run-time without ices running
been adled andthe end users ofthe product
wvivitinuxuser co.ukFRESH. FAST. FREE.
LIBRE.
N
The Document Foundation
proudly presents:
LibreOffice
the world's most advanced free software office suite
www libreoffice.orgJu, a subs
1as been relee
Or
Richard Hillesley wise
fees, Unuandinee
fsttvareforavarety
spubtcatons
‘When Tim Berners-Lee invented the World Wise
\Wieb in 1900, his proposal ~ presented the year
before ~ was that “a global hypertext space
bee created in which any network-accessible
Information could be referred to by a single
“Universal Document Identifier” (wiwas.rg/
People/Berers-Lee/ShortHistory. htm
eautifully simple. On the
server side, there were webpages written in
a typertext markup language (HTML) that
Fellowes simple conventions and rules, On the
client side, there was a browser that was able
to translate the HTML code into a readable
format. The web of browsable pages was
kitted together by hypertext links, which
became known as URLS.
‘Bemers-Lee had an unfashionable vision of
“the Webls potential to foster a global vill
not its potental to eam him a vila and a fleet
cars, but he was not the first to have that
vision. He credits his iepiration for the
to Profesor Ted Nelson, the man who coined
the term ‘hyportink’ back in the Sintios and
sctibed the whole messy conceet in Dream
ines published in 197
wwlinuxuser.co.uk.
A magic place of literary memory
Ted Nels 1 world brought togethe:
d nearly les after its original c ptio
Nelsons one of those inspiredthinkers whose invented, although notably more comglex. The
ceancopts dont aways make it into the eractical
‘weld inthe form that he would wish. For nearly
‘i dacadas he has been working on Xanadu,
‘8 mysterious computer system to beat all
ns, and a complex vision of a future reality
hat exists in a parallel uivers to ou
which has been promised at
regular irtervals for years
sy
with the release of Openkanadu, “Openkanady
‘means you can see all the parts. ti not yet
though it is intended
isa subset ofthe orginal
adefine the way we
in 1960 that
wrote Nelson,
would mir
chance 19
POF, which simulates paper, by
connections" jranadu.com)
‘About contemporary computer systems
“Todays
d.up inthe Eighties, and mised our
2 Word wide hypertext the
simulates paper. The World
(another imitation of ‘paper
orginal hypertext model with
breaking inks and no managoment of version
or contents” en.wikipedia org/wikiProject
Xanadu). Nelson that Xanadu solves
hese prabiems and mer
During the Eighties vast amounts of monoy
were pumped into Xanadu by Autodesk and
others, with the objective of coming up with
semathing akin tothe Web before the Web was
virtue of B
Xanadu was obscure and dit
rumerous attests
heleap rom concept
tina org/nade/233#tcomment-1715,
1960, Nelson enrlledon acomputer course
for the humanities, and “was struck by a vision
cof what could be’ Fr his term project, written
bier
heir work, years before the
‘Some five years later he came up with the
term Typertext. Since that date, Nelson ha
working on his fe project, a software
ramenork which would be a “magic p
of terry memory” (www 2iathvieginaedu/
elab/nf|OISSheml) named ator Coleridge's
bla Khan, and descried at length inhi 1961
ary Machines, Xanadu and was as
leroge's poem, which was famously
ed, in a sort of Reverie brou
so grain of Op taken to check a dysentery,
at a Farm House
a quarter of @ mile
ween Pocock and Linton,
1m Culbone Church, in
al of the year, 1797", ant
completed because oft
1 arial
fon busi ok’, alter which th
‘meraryo the dream escaped i
in Droam Machines, published in 197
promised that Xanadu would be relea
1976, His system, a weleora th 0 the
ideas ofthe Sts, would be used to “foster free
Neleon
“Xanadu was obscure and
difficult.
itnever made the leap
from concept to realisation”expression and emponer people where earior
formsof communication, TV, adioand print, were
largely one-vay, hierarchic, and disempowerng
In the 1987 edition of Literary Machines, the
release date was revised to 1988. In January
1968, Nelson wotein Bytemagazine that Xanadu
wouldbe completedby 1981
Amazingly, an inital version was released in
August 1999 ~ apparently to prove prior at on
had proposed years before ~ but has yet to see
any kind of a 1 dete long
since superseded by the Web we know today. A
lator manitstation of aspects of Xanadu was
known as Zigzag. Nelson wrote of Zigzag: “We
belive the computer world canbe simpitied and
Unified, Today, rcnary poople must deal with an
appalling variety of programs and mechanisms to
maintain ther information, We have discover
new simplification based on one simple concept
new, berated form of data that shows tsa in
wicinew ways.” (wwwxanadu.corvzgzag)
ran with the mad
ida to show the way to others so thatthe mad
idea may become reality - and maybe the
Neb owes more to Nelson than he is usually
croct for, Alt
mechanisms ofthe
W9)/3.nelgon htm) and ‘and
other web technologies as suboptimal, the Web
and Wikipedia. and Commons have
rendered: much of
although he did recognise the protlom o
and artists, which has yot to be resolved by the
real Word Wide Web although
toths problem, aking of et tax, was suboptimal
any number of reason
Itis perhapsall this that makes Nelson quote
Oscar Wide: "Everybody's waiting for me to dio
so they can say how much they appreciated my
work. But nobody will back me’
lelson's vision redundant,
Opinion
The latest in the Linuxcommunity
OPEN SOURCE
THE OPEN SOURCE COLUMN
Bitter tablets
Are tablet computers the way forward in the
classroom, ponders Simon.
‘Simon Brew iss scheoiay
\wtorand editor
workingacrossthe
Un Widows a
Mactsxplattorns
have children. My children goto school. The
‘schools that my children go to teach ICT. To
44060, they noed computers. A to of those
schools, there's curently 8 drive to fund a
bunch of iPad. Currently, said schools use
12 mix of desktop and laptop computers, and
feach has access to a bunch of interesting
software tools that we parents can also get
10 play around with remotely in some cases
Granted, when one of my children comes
home ard asks if we can got @ copy of said
program for home it gets a bit awkward, not
least when | check the prices, but there's
something useful think, about continuing 0
There is currently a pretty nasty bug
that stops the restoration process. The
permissions ofthe sites/defautt diroctory are
strict for security reasons, but they perplex
Drush and do nt allow itt finish its restora
process. The solution is simple, but it has to
bbe done before the execution of the drush
archive-backup command: charge the
permissions of the site/default dicectory by
‘executing the following command when you
are inside the Drupal root directory and then
take abackup:
chmod 755 sites/default/
‘You can now restore using the Orush backup file
without anyother problems, Do not forgat to fhe
the directory permissions of the site/defautt
directory aftr taking the backup. To restore the
database that you back up using drush sql-
‘dun —result-file-soneFile.sal, you should
run thefollowing command
$ drush sal-comect < soneFile. sql
12 Instalinen modus
Usually the fist madule you want to
installon a new Drupal sites the views module.
You can downoad it~ but nat enable it = with
the folowing:
'$ drush pr-downiload views
Enableitwith
S drush pr-enable views
Note that the parenabile command will ask
you to download all unmet dependencies
(of the module you are trying to enable. If
you know the exact name of a module, the
following command wil show its releases as
wall as whether itis already installed on your
Drupal site
$ drush p-releases all tools
Run Dru
pal sites with Drush
Administer a Drupal site from the command line
You can use Drush on any
Drupal site, as long as you have
direct access to its files via the
command line
113 Desbleandremove modes
Before removing @ module, itis
mandatory for the module tobe inthe disabled
state, asfolons:
$$ drush pr-disable views
The following extensions will be disabled:
views
Do you really want to continue? (yin): y
views was disabled successfully,
Uninstaling bth views and ctools modlescan bo
doneastolons:
$$ drush po-uninstall views ctools
{As you can imagine, the cools module caret bo
deleted because tisnot cently cisabled.
1G asiverss about rust
Drush is very power; therefore, you
should meaeize twice and cut once when using
it because some commands can damage the
security thedatabaseorthefles fyour sito.
Not onty can Drush be used in scripts to
automate many tasks, but also you can write
your own custom commands if you know PHP.
Enjoyexpiorng!
=Tutorial
Generate webpage templates with Go + Revel
Generate webpage
templates with Go + Revel
\mifyou submitamessagein the form, twill,
takeitto/echo andechoitback to you
Advisor
‘Sean M Tracey is»
Seatreteingette
icedrggtslagiey
Sosa
& crane
Resources
Go1.2+
Revel nitp:/revel github.io
git
Mercurial
Amodern Linux system
‘Your favourite text editor
vwvitinuxuser co.uk
A tittle while ago, we looked at some of the
features of Go ~ and itis lovely, Golang ie
Quick to write, quick to deploy
run, However, Gos new
nd delivering
quick to and defining
‘and bsteringly fas
oF Node
hacking
bash commands. Before
erminal
both Git Mercurial
vel needs both to dots funky set
installation magic. Assuming you have both
Lon tem, the fist
Uke to work with their favour
ard handling netw
nitty gritty as te
Enter Revel, an open source MVC framework
for Go, Releasedin early 2013 and just about to
hit the bigv100.
20 get github.com/revel/revel
This wil fetch the Revel framework and all of
ts dependencies for us, but before we canGenerate webpage templates with Go + Revel
Easily deal with the tricky business of creatinga server and handling network requests
Revel vs Flask
vs Node.js
Its hard to compare frameworks to each
athe, particularly when youre comparing
three afferent languages and coding
philosophies against each athe. Python and
Nodes have the advantage of boing stghtly
longer in the tooth (although not by a great
deal. Flask has the benefit of almost two
decades of mosty backwards-compatible
Python software development. meaning
that if you come across the problem,
somebody has probably already figured it
cut. Noga doesn't have the same amount
af development time, but it does have a
Ferooiously active development commun
recently the number of modes on NPM
cutnumberes the number of Ruby Gems.
That's phenomenal
ReveV/Go dovsnt have ether of these
quai... yet, What it does have is backing
from several of the largest softwere
companies in the world. Go is going to gO
a long way and Revel (an open-source
software) has had a lot of tine and love
poured into it by some very passionate
people. Though not nearly as. feature
complete, Rove i getting there and, with
LO. near.t’stheperfect tmetogetecited
start using the framework, wee going to need
to Revel command line tols too. Fortunately,
that's anather one-liner as well:
20 get github.con/revel/ond/revel
‘Jost like that, Revel is now set up on our
system, Painless, Enter:
revel help
Ifa dialog is printed then we're ready to go, but
if there's an issua, i's likely caused by Reve
being unable to find your installation of Go. To
rectify this, check that you have a $SGOPATH
variable pointing to your Go installations root
folder before goingany turt
0:
revel new [YOUR_APE_MHE]
Divein
Lets reate our first Revel app. Enter
Vola, we've just made a new Revel app. So,
what's just happened? Revel is all about
x Revel has become a fantastic
piece of kit for a Go developer to
get a capable server started up
4 system up and running as quickly
sible, By inching the new command,
Revel wil generate the basic files needed to
instantly got an app up and running. Doponding
con what youve set your SGOPATH variable as,
4 new folder vill be created in that directory
with the name that you passed when creating
the project. IF successful you should see a
prompttikethe following:
~ revel! http: //revel.github.io
Your application is reat
‘arhwmn/Go/sre/banana
You can run it ith:
revel run [YOUR_APP.NAME]
ust lke the prompt suggests lets go ahead
fandrun that app now,
revel run [YOUR APP.NAME]
ust ke that, our Revel app is ready to go andis
listening for connections ofport 8000.
OB Timeteratour
If you vist localhost: 2000 youll see a
friendly green welcoming screen professing
it works", which is lovely but revels ite of
the inner workings of our Revel app. Before
we start switching up some code, wore going
to take a look atthe default configuration and
folder structure of anew Revel ap
Head to your $GOPATH folder and in sre
find the folder with the name of your Revel
‘app. Open it up and take a look. The folders of
importance to us here are the public, app and
cont folders. Let's take a quick ook inside conf.
Here you have two files: app.conf and routes:
app.confis a standard configuration file, soit
you want to change the pot that your Revel app
listens on, define an SS certificate ar charge
your app name, etc hereis where yout doit
The routes file is slightly more interesting
As ts name suggests, this is where we would
define ary and all routes that we want our
‘app to be able to handle, a8 well as define
static files and error handling, Interestingly,
the order in which the routos are defined
determines the importance of that route
You neice for our / path the words App Index
follow the entry. This defines a controler that
will handle each individual request that hits
that end point. The logicfor our controllers can
bbe found in the app/eontrollers/app.go i.
Each controller can have a view assigned to
1 Unless we specify otherwise, the controller
will look for a template with the same name
28 tel n the appiviews/App! folder - in the
cease of our/ rout, that would be Index html
OG Mariputete tne tomptao res
Now that we know where we can find
Important things, lets look at passing. stuff
between them, Open up the Index file found
in the app/viens/App’ folder It looks just lhe
‘ordinary HTML butwitha fewiite cfferances. A
‘thetopofthe fieyoutl ee thelines:
{Geet . "title" "Hone"))
(template “header hel” 3)
This is pretty neat. In the index.html fle we
‘can set a variable in the render process that
‘our headerhtm fle will be able to use when
i's imported into the app view. If we set a
variable with
{set . "title" "Hone'y)
‘then we can have it print in headerhtml by
‘Simply ingarting itwhere it's needed, ike s,
stitle((titlen
This hints nicely at some of the more useful
Revel template keywords. if we wanted to
‘209 a series of CSS or JavaSeriot files in the
header :ntml fein Indoxihtml we would use the
“append! keyword to create or add toa Uist for
range to work through when the template was
being rendered. For instance.
Ceppend « “noreScripts" "seb joD
Ceppend « “moreScripts” "jsebrlarda js
(append « “norescripts” "jie goes on sD
would result in Revel iterating through the
entries appended and then replacing the (I)
in the headerhtml range with the name of
‘each value passed
‘There are quite @ number of keywords that
‘can be used in a Revel template, mostly for
‘the convenience of rendering HTML in place of
plaintext stings: for instance, {nib example)
wil output newline cheractors as HTML.
2
breake. Stil not all of the keywords are just
for rendering markup, we can do basic checks
before we decide to render anything atl
diy ige'status >{CF ea Haveuser Tr)
Logged in(end)}
will only display a message if the variable
Haveuserisset to tue,
OB szttoterancvarinios
Now, all this is well and good if all
we sant to do is change content based on
hard-coded values, but what do we do if we
want to pass variables from our controllers
through to our templates? Wel, that's. not
too hard, Hoad back over to our app.go fe,
‘Just after package controllers, insert the line
‘eodesimport “time"/code>. Don't forge the
quotes around time. Next, add the following
lines tothe end ofthe fie:
func (© Ao) TineQ) revel.Result
current = tine, lonQ
‘return e.Renderurrent)
>
We've just created a new controle! Unlike
the Index controller, this time were passing
through a variable to the template we render.
Inordertouse this new variable we need todo
two things: the frst is create a new template
for the endpoint and the second is declare
route forthe controller. Pop on aver to /app/
Vviews/pp and copy index.html as Time html
It’s important to remember the name of the
file needs to be the same as the controller in
‘order fr Revel to find it, otherwise we have to
‘explicitly set the template that we want it to
render to. Open up Time.html and change the
following ines:
It works!
0
hb It works!... and the current tinestanp
is (Ceurrent)}
Just ike the variables we set while importing
templates into a view, we can access the
value ofa variable withthe lovely (variable)
expression. If you want to pass through
‘more than one variable, all you have to dois
separate each valuewith a comma and access
them exactly the same way.
return c.fender(ourrent, myNane,
location, ete)Generate webpage templates with Go + Revel
Easily deal with the tricky business of creatinga server and handling network requests
ee
Recetas
Not aside, it's bocome alittle unusual to 900
8 compiled anguage running a web service.
This is largely due to most ofthe compiled
languages having been conceived in atime
before web dovelopment was realy in sing,
‘As such, things tke easy-to-use websockets
‘and the lke are tough to implement, so we
have a plethora of Nodajs/Ruby Gems!
Python modules to help us along with that
because theyhavealowerbariertoentry.
(Of course, the downside with. these
langvages is that they aren't compiled - thoy
are fast but they stil cant ute match the
performance of @ compiled language. Go
isthe best of both wari: it compiles so it
is fast but i also modern, go funky new
thingslke vebsockats aren’ problem,
Define aroute
good goss wd bo nad one fo
ton owl mie ats bense eve
Sat po afin he rue tere De
Ie cpp ars elon ar
at ine ie
jou ht purecshestoncoime. you
stones other toh
svat ocolar hand ate ana
Ther the a gig tae ul bs
handlingthe values ofa form.
7 Batefomtanding
Enter the app/views folder, create a
new file form html and insert the following