🔍 Code Extractor

class WebTemplate

Maturity: 49

Represents a SharePoint site definition or site template that is used to instantiate a site, providing access to template metadata and configuration properties.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webs/template.py
Lines:
4 - 80
Complexity:
simple

Purpose

This class encapsulates SharePoint site template information, including display properties, categorization, localization settings, and usage constraints. It provides read-only access to template metadata such as name, title, description, image URL, LCID, and various boolean flags that control where and how the template can be applied (e.g., root web only, subweb only, hidden status). The class inherits from Entity, suggesting it's part of a larger SharePoint API framework for managing SharePoint objects.

Source Code

class WebTemplate(Entity):
    """Specifies a site definition or a site template that is used to instantiate a site."""

    def __repr__(self):
        return self.name

    @property
    def description(self):
        """Gets a value that specifies the description of the list template.
        :rtype: str or None
        """
        return self.properties.get("Description", None)

    @property
    def display_category(self):
        """
        Specifies the display name for the category that this site definition configuration or site template is
        a part of.
        :rtype: str or None
        """
        return self.properties.get("DisplayCategory", None)

    @property
    def image_url(self):
        """
        Specifies the URL for the image that is associated with the site definition configuration or site template.
        :rtype: str or None
        """
        return self.properties.get("ImageUrl", None)

    @property
    def is_hidden(self):
        """
        Specifies whether the site definition configuration is displayed in the user interface for creating new sites
        :rtype: bool or None
        """
        return self.properties.get("IsHidden", None)

    @property
    def is_root_web_only(self):
        """
        Specifies whether the site definition configuration or site template can only be applied to the top-level site
        in the site collection.
        :rtype: bool or None
        """
        return self.properties.get("IsRootWebOnly", None)

    @property
    def is_sub_web_only(self):
        """
        Specifies whether the site definition configuration or site template can only be applied to subsites
        created within the site collection.
        :rtype: bool or None
        """
        return self.properties.get("IsSubWebOnly", None)

    @property
    def lcid(self):
        """
        Specifies the LCID for the site definition configuration or site template.
        :rtype: int or None
        """
        return self.properties.get("Lcid", None)

    @property
    def name(self):
        """Gets a value that specifies the display name of the list template.
        :rtype: str or None
        """
        return self.properties.get("Name", None)

    @property
    def title(self):
        """Specifies the display name for the site definition configuration or site template.
        :rtype: str or None
        """
        return self.properties.get("Title", None)

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

__init__: The constructor is inherited from the Entity base class. No explicit __init__ parameters are defined in this class. Instantiation likely requires parameters defined by the Entity parent class, which are not visible in this code snippet.

Return Value

Instantiation returns a WebTemplate object that provides property-based access to SharePoint site template metadata. All properties return either their specific type (str, bool, int) or None if the property is not set. The __repr__ method returns the template's name as a string representation.

Class Interface

Methods

__repr__(self) -> str

Purpose: Returns a string representation of the WebTemplate object using its name property

Returns: The name of the web template as a string (may be None)

Attributes

Name Type Description Scope
description str or None The description of the list template instance
display_category str or None The display name for the category that this site definition configuration or site template belongs to instance
image_url str or None The URL for the image associated with the site definition configuration or site template instance
is_hidden bool or None Indicates whether the site definition configuration is displayed in the UI for creating new sites instance
is_root_web_only bool or None Indicates whether the template can only be applied to the top-level site in the site collection instance
is_sub_web_only bool or None Indicates whether the template can only be applied to subsites created within the site collection instance
lcid int or None The LCID (Locale ID) for the site definition configuration or site template instance
name str or None The display name of the list template instance
title str or None The display name for the site definition configuration or site template instance
properties dict Dictionary containing the underlying SharePoint properties (inherited from Entity base class) instance

Dependencies

  • office365.sharepoint.entity

Required Imports

from office365.sharepoint.entity import Entity

Usage Example

# Assuming you have a SharePoint ClientContext established
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.webs.web_template import WebTemplate

# Connect to SharePoint site
ctx = ClientContext(site_url).with_credentials(credentials)

# Get available web templates
web_templates = ctx.web.get_available_web_templates(lcid=1033, do_include_cross_language=False).execute_query()

# Iterate through templates
for template in web_templates:
    print(f"Name: {template.name}")
    print(f"Title: {template.title}")
    print(f"Description: {template.description}")
    print(f"Display Category: {template.display_category}")
    print(f"Is Hidden: {template.is_hidden}")
    print(f"Is Root Web Only: {template.is_root_web_only}")
    print(f"Is Sub Web Only: {template.is_sub_web_only}")
    print(f"LCID: {template.lcid}")
    print(f"Image URL: {template.image_url}")
    print(f"String representation: {template}")

Best Practices

  • This class is read-only and provides property-based access to template metadata; do not attempt to modify properties directly
  • All properties may return None if the underlying SharePoint data doesn't contain that property, so always check for None before using values
  • The __repr__ method returns the name property, which may also be None; handle this case when using string representations
  • This class is typically instantiated by the SharePoint API framework when retrieving templates, not directly by user code
  • Use the is_root_web_only and is_sub_web_only properties to determine where a template can be applied before attempting to create a site
  • The lcid property indicates the language/locale for which the template is designed; ensure it matches your site requirements
  • Check the is_hidden property to determine if a template should be displayed in user interfaces
  • This class inherits from Entity, so it likely has additional methods and properties from the parent class for SharePoint operations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class WebTemplateCollection 78.4% similar

    A collection class for managing SharePoint site templates (WebTemplate objects), providing methods to retrieve and work with multiple web templates.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webs/template_collection.py
  • class ListTemplate 73.6% similar

    Represents a SharePoint list definition or list template that defines the fields and views for a list, providing access to list schema and metadata.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/lists/template.py
  • class Web 70.9% similar

    Represents a SharePoint site. A site is a type of SecurableObject. A group of related webpages that is hosted by a server on the World Wide Web or an intranet. Each website has its own entry points, metadata, administration settings, and workflows. Also referred to as web site.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webs/web.py
  • class WorkflowTemplate 69.9% similar

    A class representing a workflow template that is currently deployed on a SharePoint site, inheriting from the Entity base class.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/workflow/template.py
  • class SPOTenantWebTemplateCollection 69.4% similar

    A collection class that represents a set of SharePoint Online tenant web templates, inheriting from Entity and providing access to template items.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/webs/templates/collection.py
← Back to Browse