Working with Private Files and Directories
Names that are never routed
| Prefix | Meaning |
|---|---|
+ |
Framework file (+layout.ets, +middleware.ts, ...) |
_ |
Private. _private/ folders hold partials and modules. Other _ names are ignored. |
- |
Ignored (drafts, notes) |
. |
Ignored (dotfiles) |
pb_pages/
_private/ # private (not routable)
-drafts/ # ignored
helpers/ # normal folder (routable)
+middleware.ts # framework file (not routable)
+layout.ets # framework file (not routable)
index.ets # page
The _private folder
_private/ folders serve two purposes:
- Template partials, rendered with
include() - TypeScript modules and other files, loaded with
ctx.resolve()
Both use the same lookup: _private/ in the current template's folder, then each parent folder up to pb_pages/. A name starting with / looks only in pb_pages/_private/.
pb_pages/
_private/
header.ets
format.ts
products/
_private/
product-card.ets
queries.ts
index.ets
<!-- In products/index.ets -->
<%
const queries = ctx.resolve('queries') // products/_private/queries.ts
const format = ctx.resolve('format') // _private/format.ts
%>
<%- include('header') %> <!-- _private/header.ets -->
<% for (const p of queries.featured(ctx.app)) { %>
<%- include('product-card', { p, format }) %>
<% } %>
Modules
A module in _private/ is a CommonJS file:
// pb_pages/products/_private/queries.ts
module.exports = {
featured: (app) => app.findRecordsByFilter('products', 'featured = true', '-created', 10),
}
Notes
- Files in
_private/are never served. - Keep secrets in environment variables (see Managing Secrets), not in files.
- Keep private files close to where they're used, and hoist them up when several sections share them.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.