Search Docs
Loading...
Skip to content

Import Templates

Load design templates into CE.SDK from archive URLs, scene URLs, and serialized strings.

5 mins
estimated time
GitHub

Templates are pre-designed scenes that provide starting points for user projects. CE.SDK supports loading templates from archive URLs with bundled assets, remote scene URLs, or serialized strings stored in databases.

This guide covers how to load templates from archives, URLs, and strings, and work with the loaded content.

Load from Archive#

Load a template from an archive URL using loadArchive(from:). Archives are .zip files that bundle the scene with all its assets, making them portable and self-contained. The URL can point to a local file or a remote download — loadArchive(from:) accepts either.

try await engine.scene.loadArchive(from: archiveURL)

Load from URL#

Load a template from a remote .scene file URL using load(from:). The scene file is a JSON-based format that references assets via URLs, so those assets must remain reachable at their original URLs.

let templatesBase = "https://cdn.img.ly/packages/imgly/cesdk-swift/1.76.0/assets/ly.img.template/templates"
let sceneURL = URL(string: "\(templatesBase)/cesdk_postcard_1.scene")!
try await engine.scene.load(from: sceneURL)

Load from String#

For templates stored in databases or received from APIs, call load(from:) with the serialized scene string. This works with content previously produced by engine.scene.saveToString().

try await engine.scene.load(from: sceneString)

Working with the Loaded Scene#

After loading a template, retrieve the active scene and inspect or adjust the viewport.

Verify the Scene#

Use engine.scene.get() to retrieve the current scene block — it returns an optional and is nil until a scene has been loaded. Pair it with engine.scene.getPages() to list the template’s pages; pages.count tells you how many it contains.

guard let scene = try engine.scene.get() else { return }
let pages = try engine.scene.getPages()
print("Template has \(pages.count) page(s)")

Zoom to Content#

Fit the loaded template in the viewport using engine.scene.zoom(to:). The four padding parameters add space in points around the focused block.

try await engine.scene.zoom(
to: scene,
paddingLeft: 40,
paddingTop: 40,
paddingRight: 40,
paddingBottom: 40,
)

Next Steps#

  • Create From Scratch — Build reusable design templates programmatically using CE.SDK’s APIs
  • Apply Templates — Apply templates to existing scenes while preserving page dimensions