Configurations
Textwire offers several configuration options to customize its behavior. You can apply these settings in two ways:
-
Using
textwire.Configure
: Call thetextwire.Configure
function to set global configurations for the library. -
Passing to
textwire.NewTemplate
: Pass the configuration directly to thetextwire.NewTemplate
function when creating templates, allowing you to customize behavior on a per-template basis.
Setting Configurations
To learn how to set configurations using textwire.NewTemplate
, refer to the Usage with Templates guide. Below is a basic example of setting configurations with textwire.Configure
:
import (
"github.com/textwire/textwire/v2"
"github.com/textwire/textwire/v2/config"
)
func main() {
textwire.Configure(&config.Config{
TemplateDir: "templates",
TemplateExt: ".tw", // recommended to use .tw extension
})
}
In the example above the TemplateDir
and TemplateExt
make sense only if you use Textwire as a template engine for your project. For things like evaluating a single Textwire file or a string, you don't need to set these configurations.
All the configurations in Textwire are optional, because each configuration has a default value. Read more about the available configurations below.
Available Configurations
Property | Type | Description of the configuration | Default value |
---|---|---|---|
TemplateDir | string | The directory where Textwire will look for template files | "templates" |
TemplateExt | string | The extension of the template files | ".tw.html" |
ErrorPagePath | string | The relative path to the custom error page. It's relative to the TemplateDir directory. Custom error page is displayed only when DebugMode is set to false | "" |
DebugMode | bool | Is a flag to enable the debug mode. With this mode enabled you can see error messages in the browser. Read about the error handling here | false |
We recommend using the TemplateExt
setting with the .tw
extension. The .tw.html
extension is longer and may be deprecated in future major versions of Textwire.
If you are using VSCode and change the TemplateExt
setting to anything other than .tw
or .tw.html
, you will lose syntax highlighting for Textwire files provided by the Textwire extension. To retain full extension functionality, change the extension to .tw
for Textwire files.