Hoplon is great framework. I hope it will change our standart way in building web.
In next a few blog posts I will create Kalah game, and I’ll post my adventure here. To be prepared you should read excellent Getting Started Hoplon.io.
So today our task is create main menu and some blocks which we will see when certain menu chosen. These menu items will be connected with hash. Result is here.
HTML
We start with simple template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Notice, we require tailrecursion.hoplon.util
and will use route-cell
from it for creating cell updated with current hash:
1 2 3 4 |
|
In our case with-let
macro first create cell with current hash (cell (hash))
, then run setInterval
with function which will update our cell, after hash cell will be returned.
1 2 3 4 5 |
|
1
|
|
So with this library we only need in our index.html.hl
:
1
|
|
Links highlighting
I’m using bootstrap, and we need set active
class for current menu item.
So we should use do-class atribute which takes cell with hash-map like {:active true}
– do-class='{ { (cell {:active true}) }}'
.
To depend on current hash we change it to formula cell:
1 2 3 |
|
We can make a little easy by creating boolean help-cell (there also example of macro defc=
):
1 2 |
|
So now we can write links like this:
1 2 3 |
|
Hidden Content
Now we need only hide with hidden
class our div
which is not connected to current hash path.
And this is exactly like in above code with menu items (with and without our helper):
1 2 3 4 5 6 7 |
|
That is all for now.