Don’t know if this is primarily a support-question or a feature-request, but a very nice feature would be to switch between showing different programming languages in code blocks (see this ).
I’m very new to hugo, but it would be a very nice feature to have for me. Do anyone have an idea for how I can implement this, or know if something like this can already be implemented? (I’d prefer not using the leetcode-proposition shown in the stack overflow post if possible).
bwintx
August 11, 2022, 11:45am
2
The Hugo documentation does this in multiple locations, so you might just check its repo:
1 Like
idarek
August 12, 2022, 6:30am
3
as @bwintx mentioned,
look here for example:
{{< code-toggle file="config" >}}
[Params]
foo = "bar"
{{< /code-toggle >}}
and shortcode https://github.com/gohugoio/hugoDocs/blob/master/layouts/shortcodes/code-toggle.html
This is designed for JSON, TOML, and YAML formats only.
1 Like
Perfect, thank you so much!
bep
August 12, 2022, 11:33am
5
If you want to give AlpineJS a try (good match with Hugo), the shortcode above is ported to AlpineJS here:
{{ $file := .Get "file" | default "config" }}
{{ $code := "" }}
{{ with .Get "config" }}
{{ $file = $file | default "config" }}
{{ $sections := (split . ".") }}
{{ $configSection := index $.Site.Data.docs.config $sections }}
{{ $code = dict $sections $configSection }}
{{ else }}
{{ $code = $.Inner }}
{{ end }}
{{ $langs := (slice "yaml" "toml" "json") }}
<div x-data class="code code-toggle border border-gray-100 my-2 sm:my-6">
<nav
class="relative flex divide-x divide-gray-100 dark:divide-gray-800 "
aria-label="Tabs">
{{ range $i, $lang := $langs }}
<a
href="#"
x-on:click="$store.nav.userSettings.settings.configFileType = '{{ index $langs $i }}'"
class="text-gray-900 group relative min-w-0 flex-1 overflow-hidden p-3 text-sm font-medium no-underline text-center hover:bg-gray-50 focus:z-10"
This file has been truncated. show original
1 Like