Beginner here - unwanted empty line in template

As @Pch said it’s matter of white space handling, but I would also like to show a different approach to the same which I tend to use in similar cases.

<%* 
const dayAlternatives = [
  "日",
  "月",
  "火",
  "水",
  "木",
  "金",
  "土",
  ]

const dayText = "**" + dayAlternatives[tp.date.now("d")] + "** " + tp.date.now("YYYY-MM-DD dddd")

_%>
# <% dayText %>

<< **先** [[<% tp.date.now("YYYY-MM-DD dddd", -1) %>]] | **月** [[<% tp.date.now("YYYY-MM MMMM") %>]] **月** | [[<% tp.date.now("YYYY-MM-DD dddd", 1) %>]] **翌** >>

The trick in this variant is that we declare the different characters(?)/texts for the various days in a table, and then do one lookup into that table depending on which day of week it is, and use that to build up a intermediate text, dayText, for later usage.

I believe this gives a cleaner solution, where it’s easier to see what your template actually produces. It also simplifies the logic, and reduce on the complexitiy and number of calls to tp.date.now().

2 Likes