How to include files inside template/package, but parsed from project path?

File paths (EDIT: given as strings; see below for the path type) such as "/sections/preface/preface.typ" are always relative to where they are used:

// a.typ
#let my-include(path) = include path

// b.typ
#import "@local/test-template:0.1.0": my-include

#include "foo.typ"      // relative to b.typ
#my-include("foo.typ") // relative to a.typ

in your case, that means your (absolute) paths would be relative to (the package containing) functions.typ. The way around this is to not pass paths, but content to your template:

  before: ( //my list of files to include
    preface: include "/sections/preface/preface.typ",
    acknowledgement: include "/sections/preface/acknowledgement.typ",
    contents: include "/sections/preface/contents.typ",
    readers_guide: include "/sections/preface/readers_guide.typ",
  ),

path type (since 0.15)

Eventually, there should be There is now a distinct path type that lets you pass paths to other places, while retaining what they’re relative to but this doesn’t exist yet. You can read more on the topic here:

Now you could also write

  before: ( //my list of files to include
    preface: path("/sections/preface/preface.typ"),
    acknowledgement: path("/sections/preface/acknowledgement.typ"),
    contents: path("/sections/preface/contents.typ"),
    readers_guide: path("/sections/preface/readers_guide.typ"),
  ),

… and your orignal include file, where file is now a path instead of a str should work.