Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar support multiple "Taxonomy Cloud Widget" #305

Closed
dongzhuoer opened this issue Feb 20, 2021 · 3 comments
Closed

Sidebar support multiple "Taxonomy Cloud Widget" #305

dongzhuoer opened this issue Feb 20, 2021 · 3 comments

Comments

@dongzhuoer
Copy link

Currently, taxonomy_cloud.taxonomy can only take one value. Would it be possible to support both "tags widget" and "categories widget" in the sidebar?

@MunifTanjim
Copy link
Owner

You can do this:

  • Copy the minimo/layouts/partials/widgets/taxonomy_cloud.html file in your repository's /layouts/partials/widgets/taxonomy_cloud_two.html path.
  • Replace taxonomy_cloud with taxonomy_cloud_two in that file.
  • Add taxonomy_cloud_two to your sidebar's widget list in the config.toml file.

@j1mc
Copy link

j1mc commented Mar 11, 2021

Thanks for that tip here, @MunifTanjim. Here's a fully detailed explanation for how that works:

{{- $defaultConfig := .Site.Data.config.default.widgets.taxonomy_cloud_categories -}}
{{- $configData := ( or .Site.Data.config.widgets.taxonomy_cloud_categories $defaultConfig ) -}}
{{- $lang := .Site.Language.Lang -}}
{{- $config := ( ( index $configData $lang ) | default $configData ) -}}

{{- $shuffle := ( $config.shuffle | default true ) -}}
{{- $taxonomy := ( $config.taxonomy | default "categories" ) -}}
{{- $taxonomyData := ( .Site.GetPage $taxonomy ).Data -}}
{{- $taxonomySingular := $taxonomyData.Singular -}}

<section class='widget widget-taxonomy_cloud sep-after'>
  <header>
    <h4 class='title widget-title'>
      {{- ( $config.title | default ( i18n $taxonomySingular 2 ) ) -}}
    </h4>
  </header>

  {{ partial "extras/taxonomy_cloud" ( dict "Taxonomy" $taxonomy "Shuffle" $shuffle "Scope" . ) }}

</section>

And then here's the related /data/config/widgets.toml info:

# Taxonomy Cloud Widget config for Categories
[taxonomy_cloud_categories]
title = ""                            # default: Plural Name for `taxonomyCloud.taxonomy`
taxonomy = "categories"                     # default: "tags"
shuffle = true                        # default: true

Thanks for your great work on this theme.

@dongzhuoer
Copy link
Author

dongzhuoer commented Mar 29, 2021

Your comments @MunifTanjim indeed works. Yet I need to point out one more thing -- especially for a HUGO novice -- extras/taxonomy_cloud should remain unchanged when replacing taxonomy_cloud with taxonomy_cloud_two.

By the way, have you considered adding this tip somewhere in the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants