[Question] Possible get my introduction string dynamic change depend on url in term.html by using config.toml?

Hello. Sorry my question kinda confusing.

My site have 3 categories : Front End, Backend and Linux came with urls

Now the problem it. Let said i want to show the an introduction content dynamic depend on urls of page:
Example:
With /frontend: i want to have an introduction string like “Talk about Web development
With /backend : “Talk about Back-end
Example image it with /frontend


I want to do it by using config.toml.
My current term.html:

{{ define "main" }}

<div class="container">
  
 <div class="mt-2 ">
   </div>  
{{ range (.Paginator 4).Pages }}
{{ partial "postli.html" . }}
  {{ end }}
  {{ partial "pagination.html" . }}
  {{ end }}

You can add custom metadata to taxonomy: Taxonomies | Hugo

<!-- content/danh-muc/frontend/_index.md -->
---
introduction: "About Frontend"
...
---

Then you can access it from your layout:

{{ .Params.introduction }}

Hey @pointyfar . Thanks for your help once again. As usual, you always help me solve my problem. But this time, i’m facing another one. I’m not sure what is wrong from my side.

<!-- content/danh-muc/frontend/_index.md -->
---
detail: "About Frontend"
...
---

In my term.html. I’m also using pagination one. I updated with your code

{{ define "main" }}

<div class="container">
   <div class="mt-2 ">
      <h1 style="background-color:red;">
         {{ .Params.detail }}
      </h1>
   </div>
   <!-- pagenation here with 4 posts per page -->
   {{ range (.Paginator 4).Pages }}
{{ partial "postli.html" . }}
  {{ end }}
  {{ partial "pagination.html" . }}
  {{end}}  

I’m following this post to get my pagination
Pagination
Look like after i create _index.md to content/danh-muc/frontend/. My pagination is not working. It empty.

Unless I am mistaken, pagination only lists “RegularPages” which does not include sections (_index.md is a section page).

To verify try adding another (regular) page in content/danh-muc/frontend. It should show up in the pagination.

Can you guided clearer ? Sorry i’m not experienced much about pagination :cry:. So headache when coding pagination T_T :cry:

Sorry, I realized I missed the fact that frontend is a taxonomy, not a regular section.

There has been a change in terminology with taxonomies and taxonomy terms, and I’m not sure which is which at this point. Hopefully @pointyfar can help more with that.


In case it helps anyway, here is the regular pages vs list pages / section info.

Quoting from [.Site.Pages compared to .Pages](Site variables | Hugo)

  • A regular page is a “post” page or a “content” page.
  • A leaf bundle is a regular page.
  • A list page can list regular pages and other list pages. Some examples are: homepage, section pages, taxonomy term ( /tags/ ) and taxonomy ( /tags/foo/ ) pages. @bep, @pointyfar should the ‘taxonomy term’ and ‘taxonomy’ be reversed here?

So back to my issue @cshoredaniel . What should i do :(. I only want to make my tags,categories(term.html FYI) only show 4 post per page…

It would help if you showed us your git repo, or if you are unable or unwilling to do that, if you created a minimal repository that demonstrates the issue as asked in Requesting Help.

For instance, how is danh-muc configured in your config.toml, and it would be helpful to see (at least) some frontmatter of pages that use frontend. (And what are the filenames of the content pages with frontend).

Sorry for late: But here the git you requested:

My git

@cshoredaniel
For instance, how is danh-muc configured in your config.toml , and it would be helpful to see (at least) some frontmatter of pages that use frontend . (And what are the filenames of
the content pages with frontend ).

Ok my config.toml

......
[taxonomies]
    tag                    = "the"
    category           = "danh-muc"
.....

This is my content/danh-muc/frontend/_index.md

title: "FrontEnd"
detail : "Talk about Front End"

File _index.md in
content
/danh-muc/frontend`

---
title: Front End
detail: "About FrontEnd"
---

My current term.html

{{ define "main" }}
{{ $paginator := .Paginate (where .Pages "Type" "posts") }}
<div class="container">
   <div class="mt-2 ">
      <h1 style="background-color:red;">
         {{ .Params.detail }}
      </h1>
   </div>
   <!-- pagenation here with 4 post per page -->
   {{$related := .Paginate ((where site.RegularPages "Section" .Section).Related .)}}
   {{range $related.Pages}}
   {{.Title}}
   {{end}}

   {{end}}

I’m not really sure what it is you are wanting to paginate. Here’s some notes that might help with how to think about pagination:

  1. What are the pages that you want to include in the “Set of pages to paginate” ?
  2. How do you want to divide these pages into “Paginator Pages” ?

So, consider your context. You are in term.html, which is the layout that gets called when you go to yoursite.com/tags/lorem/. You can see this by putting “This is term.html” in the term.html layout and checking that this does appear in the correct place.

Slightly modifying the example here: Pagination | Hugo

This is one of the simplest code snippets you can use that will give you pagination:

{{ $paginator := .Paginate .Pages }}
{{ range $paginator.Pages }}
   {{ .Title }} 
{{ end }}
{{ template "_internal/pagination.html" . }}

Breaking this down:

{{ $paginator := .Paginate .Pages }}
                     ^        ^ Set of pages to paginate
                     Divide set of pages into Paginator Pages

This creates a Paginator by calling .Paginate on .Pages. Here, .Pages is the “Set of pages to paginate”.

Other examples might be something like (where .Pages "Section" "posts") if you want to restrict the set to only those from under /posts/:

{{ $paginator := .Paginate (where .Pages "Type" "posts") }}

Going back to your term.html.

Given tags/lorem/ as an example, the .Pages in term.html is the set of pages that have tags: "lorem" defined.


{{ range $paginator.Pages }}
   {{ .Title }} 
{{ end }}

This part of the snippet renders the subset of .Pages that are in the current .Paginator page. So, if you have 9 .Pages, with a pagination size of 2, yoursite.com/tags/lorem/ will contain the first 2 pages in .Pages, and yoursite.com/tags/lorem/page/5/ will contain the last 1.


{{ template "_internal/pagination.html" . }}

Finally, this is what renders the pagination navigation. Here, I am using the built in one, but you are of course able to write your own template.


Going back to the beginning: firstly, decide what subset of pages you want to paginate. Start simple: .Paginate .Pages, then play around with getting only a subset of this, using where and other qualifiers.

I hope this helps, and has not made things even more confusing!

2 Likes

It looks like you are trying to use the paginator twice – that won’t work. From Pagination | Hugo :

For a given Page , it’s one of the options above. The .Paginator is static and cannot change once created

Finally. I can understand a little about paginate settings of Hugo settings. Thanks @cshorsedaniel and @pointyfar for helping me. I will base on your tutorials and try it :slight_smile:

Hey finally i solved it by testing and trying over and over again.
Thanks you Mr @cshorsedaniel and Mr @pointyfar for spending time of weekend to teach me about pagination…Really appriciate :smiley:

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.