class ListTemplateCollection
A collection class that manages and provides access to SharePoint list templates, extending EntityCollection to handle multiple ListTemplate instances.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/lists/template_collection.py
6 - 23
simple
Purpose
ListTemplateCollection serves as a container and manager for SharePoint list templates. It provides methods to retrieve list templates by name and inherits collection functionality from EntityCollection. This class is used when working with SharePoint's list template system, allowing developers to query and access available templates for creating new lists. It follows the SharePoint REST API pattern for working with collections of entities.
Source Code
class ListTemplateCollection(EntityCollection):
"""Specifies a collection of list templates"""
def __init__(self, context, resource_path=None):
"""Specifies a collection of list templates"""
super(ListTemplateCollection, self).__init__(
context, ListTemplate, resource_path
)
def get_by_name(self, name):
"""
Returns the list template with the specified name.
:param str name: The specified name.
"""
return ListTemplate(
self.context, ServiceOperationPath("getByName", [name], self.resource_path)
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
EntityCollection | - |
Parameter Details
context: The client context object that provides the connection and authentication information for SharePoint operations. This is required for all API calls and is passed to child ListTemplate objects.
resource_path: Optional. The REST API resource path that identifies the location of this collection in the SharePoint site hierarchy. If not provided, defaults to None and may be constructed based on the parent context.
Return Value
Instantiation returns a ListTemplateCollection object that can be used to access and query list templates. The get_by_name method returns a ListTemplate object representing a specific template identified by name. The returned ListTemplate is configured with a ServiceOperationPath for the 'getByName' operation.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes a new ListTemplateCollection instance with the provided context and optional resource path
Parameters:
context: The client context object for SharePoint operationsresource_path: Optional REST API resource path for this collection
Returns: None (constructor)
get_by_name(self, name: str) -> ListTemplate
Purpose: Retrieves a specific list template from the collection by its name
Parameters:
name: The name of the list template to retrieve (case-sensitive string)
Returns: A ListTemplate object configured with a ServiceOperationPath for the getByName operation. The template must be loaded via execute_query() to access its properties.
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The SharePoint client context inherited from EntityCollection, used for all API operations | instance |
resource_path |
ResourcePath or None | The REST API resource path identifying this collection's location in the SharePoint hierarchy, inherited from EntityCollection | instance |
Dependencies
office365.runtime.paths.service_operationoffice365.sharepoint.entity_collectionoffice365.sharepoint.lists.template
Required Imports
from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.sharepoint.entity_collection import EntityCollection
from office365.sharepoint.lists.template import ListTemplate
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.lists.template_collection import ListTemplateCollection
# Authenticate and create context
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite').with_credentials(user_credentials)
# Get the list template collection
template_collection = ctx.web.list_templates
# Retrieve a specific template by name
custom_list_template = template_collection.get_by_name('Custom List')
ctx.load(custom_list_template)
ctx.execute_query()
# Access template properties
print(f'Template Name: {custom_list_template.name}')
print(f'Template Type: {custom_list_template.list_template_type}')
Best Practices
- Always ensure the context object is properly authenticated before instantiating this collection
- Use get_by_name() to retrieve specific templates rather than iterating through the entire collection when possible
- Call ctx.load() and ctx.execute_query() after retrieving a template to populate its properties
- The collection inherits from EntityCollection, so standard collection operations (iteration, filtering) are available
- Template names are case-sensitive when using get_by_name()
- This class is typically accessed through the web.list_templates property rather than instantiated directly
- The resource_path parameter is usually managed internally by the SharePoint client library
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class WebTemplateCollection 85.5% similar
-
class SPOTenantWebTemplateCollection 77.9% similar
-
class ListTemplate 77.9% similar
-
class ListItemCollection 71.6% similar
-
class SharingLinkDefaultTemplatesCollection 69.5% similar