× Search About Posts Code Music Links
Blank Try
experiment
lots
learn
more

Testpage

Updated on
Last site update: 8 May 2024

Testing

This uses a shortcode combined with frontmatter variables.

The page has a weight of 1 so it always appears at the top of the sidebar list.

Lesson 1 .Page

I didn’t even know .Page was a variable but this wouldn’t work without it. I was trying to range through a frontmatter array called fauna with {{ range .Page.Params.fauna }}. Without the .Page the build failed. This was from within a shortcode.

2. union

Given two arrays or slices, returns a new array that contains the elements or objects that belong to either or both arrays/slices.

Note that union produces an array that does not contain repeat values if they appear in both arrays or even twice in on array.

There is also intersect which lists only those members that are in both arrays.

3. Joining two variables

In the frontmatter there are two variables:

1goat: gary
2shark: Simon

How can we join these together? You can either make them into one variable using add or make them into an array using slice.

1{{ $two := add .Page.Params.goat .Page.Params.shark }}

To make an array instead just use slice

1{{ $two := slice .Page.Params.goat .Page.Params.shark }}

4. Using append

The append function is similar to union in that you can add to an array.

Starting with the $both variable which has already merged two arrays using union this adds a frontmatter variable goat.

 {{ $both = $both | append .Page.Params.goat }}

You can also add an array with append too:

1{{ $s = $s | append (slice "d" "e") }}
garySimon

Using union with sort: echidna, fossa, goat, pangolin, shark, skunk, striped marlin, sunfish, turbot, weasel,

Using intersect goat,

Using 10 we can see it has 10 members.

Append

Using append: shark, turbot, sunfish, striped marlin, goat, pangolin, echidna, weasel, fossa, skunk

And appending the bird array...
shark, turbot, sunfish, striped marlin, goat, pangolin, echidna, weasel, fossa, skunk, sparrow, red kite, osprey, jackdaw


range .Page.Params.fauna

goat pangolin echidna weasel pangolin fossa skunk