Skip to main content
Platform
Language

Apply a Template to a Scene

In this example, we will show you how to use the CreativeEditor SDK's CreativeEngine to apply the contents of a given template scene to the currently loaded scene through the scene API.

Setup#

This example uses the headless CreativeEngine. See the Setup article for a detailed guide. To get started right away, you can also access the block API within a running CE.SDK instance via engine.block. Check out the APIs Overview to see that illustrated in more detail.

Applying Template Scenes#

suspend fun applyTemplate(template: String)

Applies the contents of the given template scene to the currently loaded scene.

This loads the template scene while keeping the design unit and page dimensions

of the current scene. The content of the pages is automatically adjusted to fit

the new dimensions.

  • template: the template scene file contents, a base64 string.
suspend fun applyTemplate(templateUri: Uri)

Applies the contents of the given template scene to the currently loaded scene.

This loads the template scene while keeping the design unit and page dimensions

of the current scene. The content of the pages is automatically adjusted to fit

the new dimensions.

  • templateUri: the resource of the template scene file.
fun get(): DesignBlock?

Return the currently active scene.

  • Returns the scene or null, if none was created yet.
val rawResId = R.raw.cesdk_postcard_1
val rawResourcePath = context.resources.run {
ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+
getResourcePackageName(rawResId) + "/"" +
getResourceTypeName(rawResId) + "/" +
getResourceEntryName(rawResId)
}
engine.scene.applyTemplate(template = "UBQ1ewoiZm9ybWF0Ij...")
engine.scene.applyTemplate(templateUri = Uri.parse("https://cdn.img.ly/assets/demo/v1/ly.img.template/templates/cesdk_postcard_1.scene"))
engine.scene.applyTemplate(templateUri = Uri.parse("file:///android_asset/templates/cesdk_postcard_1.scene"))
engine.scene.applyTemplate(templateUri = Uri.fromFile(File(filesDir, "templates/cesdk_postcard_1.scene")))
engine.scene.applyTemplate(templateUri = Uri.parse(rawResourcePath))
engine.scene.get()