Content import, export, and setup
Builder moves authored content between a Frappe site and app source files or a central template hub. Its setup hooks load that content during install and migration, while lifecycle rules keep exported pages and their dependencies aligned with the database. Pages can also carry a staging state for route review without search indexing or sitemap inclusion.
Content transfer model
Builder uses two related transfer paths. Standard content belongs to an installed app and is represented by files that can recreate pages and their local dependencies. Template content belongs to a shipped template group and is synchronized as a catalog resource. Both paths treat the database as the runtime store and source files as the repeatable input for setup.
| Content path | Main purpose | Result |
|---|---|---|
| Standard page export | Package a page for an installed app | A page fixture with scripts, components, fonts, tokens, and copied assets |
| Standard page sync | Load app-owned Builder files | Database records and a standard project folder |
| Template group sync | Load shipped templates | Template pages and shared resources that can feed the template picker |
| Hub template import | Bring a selected template to a site | A new editable page and site-local supporting records |
The transfer code avoids writing back to app source during bulk import. This keeps install and migration as one-way load steps instead of creating source changes while the database is being updated. is_bulk_import() groups install, migrate, patch, and import activity for this guard. References: builder/utils.py• L40-59, builder/export_import_standard_page.py• L86-120
Standard page transfer
Standard pages are Builder pages marked for an app through is_standard and app. In developer mode, saving such a page exports a repeatable file set under the target app. On a later install, migration, or app install, the sync path reads that set back into Builder. References: builder/…/builder_page.json• L253-265, builder/…/builder_page.py• L330-334, builder/install.py• L5-11, builder/install.py• L22-44
Export package
The standard export package combines the page definition with the resources that the page needs to work. It uses the draft block tree when present, copies supported image and video assets into the target app, and writes page data code and client scripts beside the page fixture. Referenced components, fonts, and design tokens are exported into shared Builder file areas so another site can load the page as a unit. References: builder/export_import_standard_page.py• L22-84, builder/utils.py• L641-798
The target app must be installed. The export names are normalized so the write and delete paths point to the same directory. A page without a data script still gets an empty data-script file, which keeps the package shape stable. References: builder/export_import_standard_page.py• L24-36, builder/export_import_standard_page.py• L52-63, builder/…/test_standard_page_sync.py• L210-227
Import sequence
Standard sync scans each selected installed app. It loads shared components and scripts first, then fonts and tokens, and finally pages. The page sync creates a standard project folder for the app before it loads page records. This order gives pages access to the resources they reference. References: builder/export_import_standard_page.py• L86-120
The sync path respects the fixture timestamp when it imports records. A record that is newer in the database is not overwritten by an older file. This lets deployment bring in source changes without replacing newer site data by accident. References: builder/utils.py• L387-416
Standard content lifecycle
Standard exports follow the page and its dependencies through rename, app change, uncheck, and delete operations. Cleanup runs in developer mode because it changes app source files. A dependency is removed only when no other standard page in that app still references it. References: builder/…/builder_page.py• L252-299, builder/export_import_standard_page.py• L300-361
The lifecycle keeps ownership local to the app that uses the page. A renamed page removes the old export and writes a new one. Moving a page to another app removes the old app's package. Removing the standard flag or deleting the page removes its page files and any now-unused scripts, components, fonts, and tokens. References: builder/…/builder_page.py• L301-334, builder/…/test_standard_page_sync.py• L294-365
Page state also includes staging. A staging page is served at its route but stays hidden from search engines and the sitemap, so content can be reviewed at its real URL before it becomes live. References: builder/…/builder_page.json• L68-80
The same relationship applies when a shared resource changes. Components, client scripts, and tokens export updates to the installed apps that contain standard pages using them. Shared resources remain when another standard page still needs them. References: builder/…/builder_component.py• L40-69, builder/…/builder_client_script.py• L39-55, builder/…/builder_token.py• L42-67
Installation and migration hooks
The app hooks make setup repeatable. After install, Builder creates its upload folders, loads built-in page and block resources, loads token fixtures, prepares the analytics table index, imports standard Builder files, aligns the site AI provider with site configuration, and adds Builder to the Website sidebar when custom sidebar layers exist. After migration, it repeats the content sync, provider alignment, and sidebar setup without recreating the upload folders. When another app is installed, Builder syncs only that app's standard files. References: builder/install.py• L22-44, builder/install.py• L51-61
Before uninstall, Builder removes its Website sidebar link when a custom sidebar layer exists. This keeps the site navigation from pointing to a removed Builder entry while leaving unrelated sidebar items unchanged. References: builder/install.py• L47-76
The provider setup keeps the Frappe AI provider enabled when the site has an AI gateway key and disabled when it does not. A newly created provider receives its gateway model list and default model; a gateway listing failure is logged so install and migration can finish and retry later. References: builder/install.py• L30-39, builder/…/presets.py• L107-143
Template fixtures use a separate sync entry point. The install hooks also load built-in page templates, block templates, and Builder tokens, while the template module handles shipped template groups. When changing setup, keep both setup paths aligned so content is available after a fresh install and after an upgrade. References: builder/install.py• L4-11, builder/install.py• L22-40, builder/template_sync.py• L19-27, builder/template_sync.py• L70-100
Template synchronization
A template group is a shipped set of pages that shares Builder components and tokens. Its committed fixtures define the group, while a manifest supplies human-facing group data and page order. Sync imports the shared resources before the pages and then restores template markers and publish state. References: builder/template_sync.py• L1-27, builder/template_sync.py• L70-132
The template catalog distinguishes shipped templates from user-created templates. Shipped pages have both is_template and template_group; pages with only is_template remain user-owned. In production, a successful sync removes shipped template pages whose fixtures were removed from disk, but it does not prune a group that failed to sync or shared resources that may still be used. References: builder/template_sync.py• L135-159
Template export is a developer workflow for publishing a whole group. Saving a shipped template page exports the group's pages and shared resources, updates the manifest, and copies page assets into a group-specific public area. Preview generation is helpful but not required for the export to complete. References: builder/…/builder_page.py• L229-241, builder/template_sync.py• L164-241, builder/template_sync.py• L317-360
Hub template provisioning
The site can fetch a live catalog from a central Builder Hub and turn a selected template into editable site content. The server fetches the bundle, imports its fonts, tokens, and components, then creates a new page from the bundle's blocks and page settings. Page scripts are copied into new site-local script records. References: builder/api.py• L447-483, builder/api.py• L486-538
The provisioning flow supports one page or every page in a template group. A hub failure produces an error for a single-page request; group import skips pages whose bundles fail and errors only when it creates none. Imported pages hot-link hub images when the bundle provides them. If a page has no preview, Builder schedules preview generation after the transaction commits. References: builder/api.py• L486-585
This sequence shows how a hub selection becomes editable site content.
flowchart LR
A[Template catalog] --> B[Selected page or group]
B --> C[Fetch page bundle]
C --> D[Import shared resources]
D --> E[Create editable page]
E --> F[Attach page scripts]
F --> G[Generate missing preview]
User invitation lifecycle
Builder uses Frappe's user invitation service to grant Builder access through the Website Manager role. The settings view shows active Builder members and pending invitations, and it lets an authorized user send, resend, or cancel invitations. References: builder/hooks.py• L100-123, frontend/…/GlobalUsers.vue• L1-88
The invitation view treats the server as the source of membership state. It lists pending invitations for the Builder app and active enabled system users with Website Manager or System Manager roles. The invite response separates new invites, existing pending invites, current members, and disabled users so the operator can act on each outcome. References: builder/api.py• L352-392, frontend/…/GlobalUsers.vue• L118-214
Invitation creation and acceptance also emit Builder telemetry. These events observe access flow only; they do not provision page content. References: builder/user_invitation.py• L1-13
Related pages
- Builder server domain — parent overview of the server domain.
- Builder content documents — persisted pages and supporting records.
- Server API and events — request and event interfaces around these flows.
- Website rendering and publishing — how imported content becomes website output.
- Site configuration and design tokens — shared tokens and site design settings.
- Builder access and analytics — access control and telemetry context.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep standard export and cleanup naming rules aligned. A change to the export directory shape can leave stale app files behind.
- Keep the standard sync order aligned with page dependencies. Pages must load after the components, scripts, fonts, and tokens they reference.
- Keep bulk-import guards aligned with every document hook that can write source files or start background work. Install and migration must not rewrite app fixtures.
- Keep template fixture markers and reconciliation rules aligned. A change to
is_templateortemplate_groupcan change which pages are read-only or deleted during sync. - Keep hub bundle fields aligned with site-local record creation. A missing resource or preview field can produce an editable page with broken supporting content.
- Keep invitation role rules aligned between the hook and the invitation request. A mismatch can show a user as invited without granting the intended Builder access.
- Keep the
stagingpage state aligned with route and indexing behavior. Staging pages must remain route-served while staying out of search results and the sitemap. - Keep install, migration, and uninstall hooks aligned with site configuration and navigation. Setup must not depend on gateway model-list availability, and removal must not leave a Builder sidebar link behind.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Target app is not installed during standard export | Builder cannot write the package | Validate the target app before export and use installed apps for cleanup |
| Standard sync runs while a page or dependency hook exports files | App source can be changed during install or migration | is_bulk_import() suppresses export and background edit work |
| A template group fails part way through sync | One group's catalog can be incomplete | Isolate group errors and reconcile only groups that completed successfully |
| A template fixture is removed from disk in production | The corresponding shipped page is deleted from the site | Reconcile only is_template pages with a template_group; leave user templates alone |
| A shared standard dependency is used by another page | Deleting one page could break the other page's package | Remove dependency files only when no other standard page in the app references them |
| Hub catalog or bundle fetch fails | A selected template cannot be provisioned, or a group may import only some pages | Return a clear single-page error and reject a group when no page was created |
| Invitation targets a disabled user or an existing member | No new access is granted | Surface separate response lists for disabled, pending, and accepted addresses |
| A staging state is lost during page transfer | A review page can become visible to search engines or enter the sitemap | Preserve the staging state with the page record and keep it separate from published |
| AI gateway model listing fails during setup | The provider is ready but its initial model list can be empty | Log the listing error and allow the next model-list load to retry |
| Builder is uninstalled while its Website sidebar item remains | Site navigation can keep a link to an unavailable Builder entry | Remove only Builder's sidebar URL during before_uninstall when a custom sidebar layer exists |
Key files
| File | Why to read it |
|---|---|
| builder/export_import_standard_page.py | Defines the standard page package, dependency export, app sync, and cleanup model. |
| builder/install.py | Shows the install, migration, per-app setup, Website sidebar, and uninstall sequence. |
| builder/…/presets.py | Defines site-config-driven AI provider setup during install and migration. |
| builder/template_sync.py | Defines shipped template group import, export, preview assets, and reconciliation. |
| builder/api.py | Defines hub template provisioning, page duplication, and invitation-facing server reads. |
| builder/…/builder_page.py | Connects page save, rename, app change, delete, and template events to transfer behavior. |
| builder/…/builder_page.json | Defines page states and the fields that travel with a Builder page, including standard, template, and staging markers. |
| builder/…/builder_component.py | Shows how shared component changes reach standard page packages. |
| builder/…/builder_token.py | Shows how token changes reach standard page packages. |
| builder/…/builder_client_script.py | Shows how page script changes reach standard page packages. |
| frontend/…/GlobalUsers.vue | Shows the operator flow for Builder members and invitations. |
| builder/hooks.py | Declares setup and invitation integration points. |