file.MigrateFrom
MigrateFrom parses blocks from the provided file as if they originated from this template. This is useful when you want to move a file, but keep its contents. This should be called before any other functions are called inside of the file.
This function only takes effect if the old file (path) exists.
Note: Only blocks are persisted. Unlike [MigrateTo] the file is not actually copied to disk.
Example old.go:
go
package main
import "fmt"
## <<Stencil::Block(main-function)>>
func main() {
fmt.Println("Hello from migrated code!")
}
## <</Stencil::Block>>Example new.go.tpl:
go
{{ file.MigrateFrom "old.go" -}}
package main
import "fmt"
## <<Stencil::Block(main-function)>>
{{ file.Block "main-function" }}
## <</Stencil::Block>>Example new.go:
go
package main
import "fmt"
## <<Stencil::Block(main-function)>>
func main() {
fmt.Println("Hello from migrated code!")
}
## <</Stencil::Block>>Result: The block content from old.go is preserved in new.go
