/**
  * Apply a core template.
  *
  * @since 1.0
  * @since 1.5.7. Added logic for overriding core templates.
  * @param int $index The index of the template to apply.
  * @param bool $append Whether to append the new template or replacing the existing layout.
  * @return void
  */
 public static function apply_template($index = 0, $append = false)
 {
     // Apply a user defined template if core templates are overriden.
     if (class_exists('FLBuilderTemplatesOverride')) {
         $success = FLBuilderTemplatesOverride::apply($index, $append);
         if ($success) {
             return;
         }
     }
     // Apply a core template.
     $template = self::get_template($index);
     $row_position = self::next_node_position('row');
     // Delete existing nodes and settings?
     if (!$append) {
         self::delete_layout_data('draft');
         self::delete_layout_settings('draft');
     }
     // Only move forward if we have template nodes.
     if (isset($template->nodes)) {
         // Get new ids for the template nodes.
         $template->nodes = self::generate_new_node_ids($template->nodes);
         // Get the existing layout data and settings.
         $layout_data = self::get_layout_data();
         $layout_settings = self::get_layout_settings();
         // Reposition rows?
         if ($append) {
             foreach ($template->nodes as $node_id => $node) {
                 if ($node->type == 'row') {
                     $template->nodes[$node_id]->position += $row_position;
                 }
             }
         }
         // Merge and update the layout data.
         $data = array_merge($layout_data, $template->nodes);
         self::update_layout_data($data);
         // Merge and update the layout settings.
         if (isset($template->settings)) {
             $settings = self::merge_layout_settings($layout_settings, $template->settings);
             self::update_layout_settings($settings);
         }
     }
     // Delete old asset cache.
     self::delete_asset_cache();
 }