Discussion:
[hakyll] Easy way to check if we are active in navigation?
h***@gmail.com
2015-01-09 18:37:52 UTC
Permalink
Hi,

is there an easy way to check if we are within the navigation to mark a
menu entry as 'active', either in the main nav where i have a ul/li list in
template/default.html, something like $if(isactive)$class="active"$endif$,
or in sub navigations, like the blog example: $for(posts)$<li
$if(isactive)$class="active"$endif$ ><a href="$fullurl$">.....

well, not a big fan of google groups, i wonder if the examples above come
out correct ;)
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2015-01-09 18:52:43 UTC
Permalink
I have something like that in a site I did.

In my template, I would have:

<a href="foo.html" class="$activeClass("foo.html")$">
foo
</a>

And then the code implementing this function:

activeClassField :: Context a
activeClassField = functionField "activeClass" $ \[p] _ -> do
path <- toFilePath <$> getUnderlying
return $ if path == p then "active" else "inactive"

Then you add this to your `Context`. It might need some adaptation but
that's the basic idea I think.

Hope this helps,
Peace,
Jasper
Post by h***@gmail.com
Hi,
is there an easy way to check if we are within the navigation to mark a
menu entry as 'active', either in the main nav where i have a ul/li list in
template/default.html, something like $if(isactive)$class="active"$endif$,
or in sub navigations, like the blog example: $for(posts)$<li
$if(isactive)$class="active"$endif$ ><a href="$fullurl$">.....
well, not a big fan of google groups, i wonder if the examples above come
out correct ;)
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kyle Marek-Spartz
2015-02-08 17:10:25 UTC
Permalink
I wasn't able to get this to work, but this JavaScript accomplishes the
same, for the most part.

<script>
(function() {
var navLinks = document.querySelectorAll("nav ul li a");
for (var i = 0; i < navLinks.length; i++) {
if (navLinks[i].href == window.location.href) {
navLinks[i].classList.add("active");
}
}
})();
</script>
Post by Jasper Van der Jeugt
I have something like that in a site I did.
<a href="foo.html" class="$activeClass("foo.html")$">
foo
</a>
activeClassField :: Context a
activeClassField = functionField "activeClass" $ \[p] _ -> do
path <- toFilePath <$> getUnderlying
return $ if path == p then "active" else "inactive"
Then you add this to your `Context`. It might need some adaptation but
that's the basic idea I think.
Hope this helps,
Peace,
Jasper
Post by h***@gmail.com
Hi,
is there an easy way to check if we are within the navigation to mark a
menu entry as 'active', either in the main nav where i have a ul/li list
in
Post by h***@gmail.com
template/default.html, something like
$if(isactive)$class="active"$endif$,
Post by h***@gmail.com
or in sub navigations, like the blog example: $for(posts)$<li
$if(isactive)$class="active"$endif$ ><a href="$fullurl$">.....
well, not a big fan of google groups, i wonder if the examples above
come
Post by h***@gmail.com
out correct ;)
--
You received this message because you are subscribed to the Google
Groups "hakyll" group.
Post by h***@gmail.com
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
frantisek kocun
2015-02-12 23:59:40 UTC
Permalink
Helped even to me. Thx Jasper
Post by Jasper Van der Jeugt
I have something like that in a site I did.
<a href="foo.html" class="$activeClass("foo.html")$">
foo
</a>
activeClassField :: Context a
activeClassField = functionField "activeClass" $ \[p] _ -> do
path <- toFilePath <$> getUnderlying
return $ if path == p then "active" else "inactive"
Then you add this to your `Context`. It might need some adaptation but
that's the basic idea I think.
Hope this helps,
Peace,
Jasper
Post by h***@gmail.com
Hi,
is there an easy way to check if we are within the navigation to mark a
menu entry as 'active', either in the main nav where i have a ul/li list
in
Post by h***@gmail.com
template/default.html, something like
$if(isactive)$class="active"$endif$,
Post by h***@gmail.com
or in sub navigations, like the blog example: $for(posts)$<li
$if(isactive)$class="active"$endif$ ><a href="$fullurl$">.....
well, not a big fan of google groups, i wonder if the examples above
come
Post by h***@gmail.com
out correct ;)
--
You received this message because you are subscribed to the Google
Groups "hakyll" group.
Post by h***@gmail.com
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...