ArcGIS Pro 2.9 API Reference Guide
GetTemplates(Layer) Method
Example 

ArcGIS.Desktop.Mapping Namespace > MappingExtensions Class > GetTemplates Method : GetTemplates(Layer) Method
the layer to retrieve templates from.
Gets all templates for a layer.
Syntax
public static IEnumerable<EditingTemplate> GetTemplates( 
   Layer layer
)
Public Overloads Shared Function GetTemplates( _
   ByVal layer As Layer _
) As IEnumerable(Of EditingTemplate)

Parameters

layer
the layer to retrieve templates from.

Return Value

An enumeration of templates.
Remarks
If called on the MCT and templates are not yet loaded the templates will load and be returned. If called on the UI thread and templates are not yet loaded, the return value will be empty even though (unloaded) templates may exist for the layer. See also AreTemplatesLoaded(Layer)
Example
QueuedTask.Run(() =>
{
  //hide all tools except line tool on layer
  var featLayer = MapView.Active.Map.FindLayers("Roads").First();

  var editTemplates = featLayer.GetTemplates();
  var newCIMEditingTemplates = new List<CIMEditingTemplate>();

  foreach (var et in editTemplates)
  {
    //initialize template by activating default tool
    et.ActivateDefaultToolAsync();
    var cimEditTemplate = et.GetDefinition();
    //get the visible tools on this template
    var allTools = et.ToolIDs.ToList();
    //add the hidden tools on this template
    allTools.AddRange(cimEditTemplate.GetExcludedToolDamlIds().ToList());
    //hide all the tools then allow the line tool
    cimEditTemplate.SetExcludedToolDamlIds(allTools.ToArray());
    cimEditTemplate.AllowToolDamlID("esri_editing_SketchLineTool");
    newCIMEditingTemplates.Add(cimEditTemplate);
  }
  //update the layer templates
  var layerDef = featLayer.GetDefinition() as CIMFeatureLayer;
  // Set AutoGenerateFeatureTemplates to false for template changes to stick
  layerDef.AutoGenerateFeatureTemplates = false;
  layerDef.FeatureTemplates = newCIMEditingTemplates.ToArray();
  featLayer.SetDefinition(layerDef);
});
Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

See Also

Reference

MappingExtensions Class
MappingExtensions Members
Overload List