In this example, we will demonstrate how to use the CreativeEditor SDK’s CreativeEngine to manage placeholder behavior and controls through the block API.
Placeholder Behavior and Controls#
public func supportsPlaceholderBehavior(_ id: DesignBlockID) throws -> BoolQuery if the given block supports placeholder behavior.
- id:: The block to query.
- Returns: true, if the block supports placeholder behavior.
public func setPlaceholderBehaviorEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the placeholder behavior for a block.
- id: The block whose placeholder behavior should be enabled or disabled.
- enabled: Whether the behavior should be enabled or disabled.
public func isPlaceholderBehaviorEnabled(_ id: DesignBlockID) throws -> BoolQuery if the given block has placeholder behavior enabled.
- id:: The block to query.
- Returns: true, if the block has placeholder behavior enabled.
public func setPlaceholderEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the placeholder function for a block.
- id: The block whose placeholder function should be enabled or disabled.
- enabled: Whether the function should be enabled or disabled.
public func isPlaceholderEnabled(_ id: DesignBlockID) throws -> BoolQuery whether the placeholder function for a block is enabled.
- id:: The block whose placeholder function state should be queried.
- Returns: The enabled state of the placeholder function.
public func supportsPlaceholderControls(_ id: DesignBlockID) throws -> BoolChecks whether the block supports placeholder controls.
- id:: The block to query.
- Returns: true, if the block supports placeholder controls.
public func setPlaceholderControlsOverlayEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the visibility of the placeholder overlay pattern for a block.
- id: The block whose placeholder overlay should be enabled or disabled.
- enabled: Whether the placeholder overlay should be shown or not.
public func isPlaceholderControlsOverlayEnabled(_ id: DesignBlockID) throws -> BoolQuery whether the placeholder overlay pattern for a block is shown.
- id:: The block whose placeholder overlay visibility state should be queried.
- Returns: the visibility state of the block’s placeholder overlay pattern.
public func setPlaceholderControlsButtonEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the visibility of the placeholder button for a block.
- id: The block whose placeholder button should be enabled or disabled.
- enabled: Whether the placeholder button should be shown or not.
public func isPlaceholderControlsButtonEnabled(_ id: DesignBlockID) throws -> BoolQuery whether the placeholder button for a block is shown.
- id:: The block whose placeholder button visibility state should be queried.
- Returns: the visibility state of the block’s placeholder button.
Full Code#
Here’s the full code:
// Check if block supports placeholder behaviorif try engine.block.supportsPlaceholderBehavior(block) {  // Enable the placeholder behavior  try engine.block.setPlaceholderBehaviorEnabled(block, enabled: true)  let placeholderBehaviorIsEnabled = try engine.block.isPlaceholderBehaviorEnabled(block)}
// Enable the placeholder capabilities (interaction in Adopter mode)try engine.block.setPlaceholderEnabled(block, enabled: true)let placeholderIsEnabled = try engine.block.isPlaceholderEnabled(block)
// Check if block supports placeholder controlsif try engine.block.supportsPlaceholderControls(block) {  // Enable the visibility of the placeholder overlay pattern  try engine.block.setPlaceholderControlsOverlayEnabled(block, enabled: true)  let overlayEnabled = try engine.block.isPlaceholderControlsOverlayEnabled(block)
  // Enable the visibility of the placeholder button  try engine.block.setPlaceholderControlsButtonEnabled(block, enabled: true)  let buttonEnabled = try engine.block.isPlaceholderControlsButtonEnabled(block)}