Don't display first row of csv file using getCSV

Hello,

I have a large csv file and am currently displaying the contents using getCSV which works great. However, I don’t want to display the first line (the column headers). Is there a way to have getCSV show rows 2 -> on??

I know I can just delete the line before displaying, but I rather not go through that step manually.

Many thanks.

Given file csv/animals.csv.

animal,sound
dog,bark
cat,meow
sheep,baah

You can skip the first row by checking if the row index is 0.

{{ $csv := getCSV "," "csv/animals.csv" }}

{{ range $index, $row := $csv }}
  {{ if ne $index 0 }}
    {{ print $index " " $row }}
  {{ end }}
{{ end }}

zwbetz,

Tx. so much, worked like a charm!

1 Like