Hi guys,
I want to create code for pagination - BreadcrumbList via Schema.org. It should be automatically build for every single page with one block of code.
So I adjusted hugo breadcrumb navigation from this example in Hugo doc like this:
how to create counter for key “position” if there is not range function? Now is {{ $i }} but it is valid only for first position and there has to be something like add $i 1 for another loop.
how to remove , in last iteration (I mean , after penultimate })
You mean dynamic, and not dynamical. You’d like your breadcrumbs generated each time, but you would not like the method by which it is generated to change.
Sorry, my friends and I have been on a words kick lately. Good luck on getting help!
Well, I mean “dynamic” = one code valids for all url. Yes, not really good word in this case (remove from title…).
All (two or three) BreadcrumbList solutions in discourse.gohugo.io don’t meet requirements.
For example, this one just cut .Page url and creates item - name from that url. It doesn’t reflect real breadcrumb navigation on page.
So you cannot have different item url and item name (as is usuall).
Also if you use short url, this method is useless (i.e. if you use url: yourdomain.com/product-name instead of long url yourdomain.com/category/subcategory/product-name ).
So I just hoped to get here some working general method.
{{ range $i, $e := . }}
{{ if $i }}/{{ end }}
<a href="{{ "tags/" | absURL }}{{ $e | urlize }}" rel="tag">{{ $e }}</a>
{{ end }}
The second line will add a slash, but ONLY if we are at item 2 and following. You could reuse that for your range. But look at the range command. The $i is an integer starting at 0 that goes up each iteration.
@ju52@davidsneighbour thansk for reply. I use couple of counters and symbol removing codes on my websites but only together with range.
In breadcrumbnav code I dont know what cause that loop and how to detect template breadcrumbnav on the first position and after template breadcrumbnav on the second position etc. This is probably the main problem.
Hi guys,
I paid to one programmer guy (symbolic amount of money). In cooperation with him, we finaly found good solution for automatic breadcrumbList ld+json. I share it with Hugo community.
Resulting code is very robust and applicable for most of situations.