Simplify my code with custom variables?

Hi guys

I have this itunes.toml in my data folder:

ranking = [ "/songs/luke-bryan/drink-a-beer.md", "/songs/dan-+-shay/10000-hours.md" ]

I want to get rid of /songs/ and .md in my itunes.toml urls so the url will be luke-bryan/drink-a-beer only. Can i add them in the code below somehow?

{{ range .Site.Data.itunes.ranking }}
{{ $page := $.Site.GetPage . }}
{{ with $page }}
{{ .Title }} , {{ .Permalink }}
{{ end }}
{{ end }}

“/songs” + URL + “.md”. How I do that? Thanks guys.

Use print and printf:

{{ print "/songs" .URL ".md" }}
{{ printf "/songs%s.md" .URL }}
1 Like

PS - Your ranking is also correct. :smile:

2 Likes

thank you for your quick reply :slight_smile:

I can’t figure out where to put it in the code…

{{ range .Site.Data.itunes.ranking }}
{{ $page := $.Site.GetPage . }}
{{ with (printf "/songs/%s.md") .$page }}
{{ .Title }} , {{ .Permalink }}
{{ end }}
{{ end }} 

That doesn’t work… hmmm

It’s working already!

{{ $page := $.Site.GetPage ( printf "/songs/%s.md" . ) }}

this is it… thanks moorereason :slight_smile:

1 Like

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