Example 22: The Context Field

Controlling which content directory resolves each token

What Is the Context Field?

By default, SSI resolves include tokens using the name of the page being processed. A page called product-laptop.html gets its tokens from a subdirectory named product-laptop/.

The context field overrides this. You can tell a step to always resolve from a fixed directory — regardless of which page is currently being built.

Three Resolution Strategies

context = "_" — root context

All pages resolve tokens from the include source’s root directory. Use this for truly global content like site headers and footers — content that should be identical on every page.

context = "product" — named context

All pages resolve tokens from content/product/. Use this when a group of related pages should share content (all product pages share the same warranty disclaimer, for example).

No context field — default behavior

SSI uses the page’s filename as the lookup key. product-laptop.html gets content from product-laptop/. Use this for content that is truly specific to one page.

See It in Action

The demo page uses all three strategies at once and labels each widget with where its content came from.