Namespaces reference
Overview
A namespace is a globally accessible template data object.
Namespaces are created by adding data files to the website data
directory (see site.config.data_dir
).
Custom data namespaces are accessible to layouts via their namespace identifier (i.e. data.<identifier>
).
Examples
Namespaces are a useful tool for content that we might need to access across multiple pages. Instead of overloading our website configuration file with custom properties, we can split global website content out into discrete namespaces data files.
1---
2namespace: newsletter
3title: 💬 Join the community
4description: |
5 Stay up-to-date with the lastest releases and other news from Team HyperTemplates.
6 Ask the developers questions, get help from the community, and share your creations! 🎨
7form:
8 action: https://hypertexting.community/signup
In this example we have created a newsletter
namespace that is accessible from layouts as the data.newsletter
property.
Properties
- Namespace identifier
- The identifier or key used to access namespace data via the global
data
object.Namespaces are identified as follows:
- using the top-level "namespace" property (if set), or...
- using the name of the top-level property (if only one top-level property is set), or...
- as "default"
In the following example, a single top-level property (
newsletter
) is used as an identifier:1--- 2newsletter: 3 title: 💬 Join the community 4 description: | 5 Stay up-to-date with the lastest releases and other news from Team HyperTemplates. 6 Ask the developers questions, get help from the community, and share your creations! 🎨 7 form: 8 action: https://hypertexting.community/signup
This example is effectively identical to the first example on this page. Both namespaces are accessible to layouts as
data.newsletter
, and they both contain the samedata.newsletter.title
,data.newsletter.description
, anddata.newsletter.form.action
properties.NOTE: duplicate namespace identifiers will result in unexpected behavior. As a best practice, we recommend using namespace data filenames as namespace identifiers. For example the
data/newsletter.yaml
namespace data file should use thenewsletter
namespace identifier.