Is there any way to set a temporary variable in Statamic? I'm used to being able to do this in twig with the {% set variable = value %} tag.

I am working on building a timeline, and to build it I need to keep track of the year that the current item has. The process usually goes like this in my code:

  1. Set the year for the first item.
  2. Display the year along with the first item
  3. Check the next item to see if the year is different. If so, then we need to display the year again.
  4. If not, then we can just display the next item.

I'm not entirely sure how else to explain it. I haven't seen anything in the documentation that would help with my situation. I'm really new to Statamic and the templating language is a lot different than Twig, which is what I'm used to.

Answered by Erin Dalzell! Go to answer.