Skip to main content
Glama

create_from_template

Generate new notes in Obsidian using predefined templates to maintain consistent formatting and structure across your vault.

Instructions

Create a new note from a template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
new_note_pathYes
template_pathYes
titleNo

Implementation Reference

  • Core handler function in ObsidianVault class that reads the template note, applies string replacements to content and frontmatter, and creates the new note using create_note method.
    async def create_from_template( self, template_path: str, new_note_path: str, replacements: dict[str, str] | None = None, ) -> None: """ Create a new note from a template. Args: template_path: Path to the template note new_note_path: Path for the new note replacements: Dict of placeholder -> value replacements Raises: FileNotFoundError: If template doesn't exist """ # Read template template = await self.read_note(template_path) content = template.content frontmatter = template.frontmatter.copy() if template.frontmatter else None # Apply replacements if replacements: for placeholder, value in replacements.items(): content = content.replace(f"{{{{{placeholder}}}}}", value) # Also replace in frontmatter values if frontmatter: for key, fm_value in frontmatter.items(): if isinstance(fm_value, str): frontmatter[key] = fm_value.replace(f"{{{{{placeholder}}}}}", value) # Create new note self.create_note(new_note_path, content, frontmatter)
  • MCP tool registration via @mcp.tool decorator and wrapper handler that provides default replacements (date, time, datetime, title) and calls the vault implementation.
    @mcp.tool(name="create_from_template", description="Create a new note from a template") async def create_from_template(template_path: str, new_note_path: str, title: str = "") -> str: """ Create a note from a template. Args: template_path: Path to the template note new_note_path: Path for the new note title: Optional title to replace {{title}} placeholder Returns: Success message """ if not template_path or not new_note_path: return "Error: Template path and new note path are required" context = _get_context() try: # Build replacements replacements = { "date": datetime.now().strftime("%Y-%m-%d"), "time": datetime.now().strftime("%H:%M"), "datetime": datetime.now().strftime("%Y-%m-%d %H:%M"), } if title: replacements["title"] = title await context.vault.create_from_template(template_path, new_note_path, replacements) return f"✓ Created note from template: {new_note_path}" except FileNotFoundError: return f"Error: Template not found: {template_path}" except FileExistsError: return f"Error: Note already exists: {new_note_path}" except Exception as e: logger.exception("Error creating from template") return f"Error creating from template: {e}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/getglad/obsidian_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server