Global markers should be replaced as early as possible

There are some global markers, like ###TOTAL_RECORDS### which can be replaced as the first thing in the template, so that they are available outside of any loop. This is useful, for example, for having a general IF statement wrapped around the whole template.