Table of page's translations using "range"

Hi I want to make a template in form of a table that list all my article, and shows if the article is translated in the language by adding a “X” on the column of that language.

I created my header that lists all my languages (11) and I can find the translations for each article but I don’t manage to line up the language in the right column.

Here is my code. I’m getting the following error execute of template failed at <.AllTranslations>: can’t evaluate field AllTranslations in type *langs.Language , I guess because of iterating {{All Translations}} inside {{ .Sites.language}}. I’ve tried many combinations but find myself stuck…

<table>
    <tr>
      <th>Article title / slug</th>
    {{ range  .Site.Languages}} 
    
      <th>{{ .LanguageName}} ({{ .Lang}}) <br> </th>
 
    {{ end }}
    
    </tr>
    {{ $allpages := where .Site.RegularPages  "Params._build.list" "!=" "never" }} 
    {{ range $allpages.ByDate.Reverse }}
    <tr>
      <td><a href="{{.Permalink}}" rel="bookmark" title="{{.Title}}">{{.LinkTitle}}</a><br>
        <code>{{ .File.Dir }}</code>
    </td>
    
    {{ range  .Site.Languages}} 
    {{ $curl := .Lang}}
    <td>
    {{ range .AllTranslations  }}
     {{if eq  $curl .Lang}}X (is translated) {{else }} (not translated){{end}}
    {{end}}
  </td>
    {{end}}
       
  </tr> 

  </table>

You have a context problem. AllTranslations is a method on Page.

Change this:

{{ range $allpages.ByDate.Reverse }}

to this:

{{ range $p := $allpages.ByDate.Reverse }}

And this:

{{ range .AllTranslations  }}

To this:

{{ range $p.AllTranslations  }}
1 Like

Thanks a lot!

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