Skip to content

EndlessTrax/python-template-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python Template Snippets Logo

Python Template Snippets

✨ Supercharge your template development workflow ✨

A comprehensive VS Code snippet collection for Jinja2 and Django template engines.

GitHub stars VS Code Marketplace License: MIT


πŸš€ Why Use This Extension?

Writing template code can be tedious with all those brackets, tags, and syntax. This extension eliminates the repetitive typing by providing smart, tab-completion snippets for common Jinja2 and Django template patterns.

Stop typing this:

{% for item in items %}
  <!-- your code -->
{% endfor %}

Start typing this:

ptfor β†’ Tab β†’ Fill in the blanks!

✨ Features

  • 🎯 20+ carefully crafted snippets for Jinja2 and Django
  • ⚑ Lightning-fast - Type pt prefix and let IntelliSense do the rest
  • 🎨 Smart cursor positioning - Jump to exactly where you need to type
  • πŸ”„ Multi-cursor support - Tab between placeholders seamlessly
  • πŸ› οΈ Framework-agnostic - Works with Flask, Django, FastAPI, and any Python web framework
  • πŸ“¦ Zero configuration - Works out of the box

πŸ“¦ Installation

From VS Code Marketplace (Recommended)

  1. Open VS Code
  2. Press Ctrl+P / Cmd+P
  3. Type ext install RickyWhite.python-template-snippets
  4. Press Enter and reload VS Code

Manual Installation

  1. Download the latest .vsix from Releases
  2. Open VS Code
  3. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  4. Click the ... menu β†’ Install from VSIX
  5. Select the downloaded file

🎯 Quick Start

  1. Open any HTML file in VS Code
  2. Type pt to see available snippets
  3. Select a snippet from the IntelliSense menu (or type the full prefix)
  4. Press Tab to trigger the snippet
  5. Fill in the placeholders and press Tab to jump between them

πŸ’‘ Pro Tip

Enable tab completion in your VS Code settings for the best experience:

{
  "editor.tabCompletion": "on"
}

πŸ“š Snippet Reference

All snippets use the pt prefix (short for "Python Template"). Here's the complete reference:

🌐 General Snippets

Works with both Jinja2 and Django

Prefix Description Output
ptnew New HTML template file Complete template with extends and blocks
ptvar Template variable {{ variable }}
ptfilt Variable with filter {{ variable | filter }}
ptcode Code block tag {% code %}
ptblock Block tag {% block name %}...{% endblock %}
ptext Extends tag {% extends 'base.html' %}
ptsup Super function {{ super() }}
ptfor For loop {% for item in items %}...{% endfor %}
ptif If statement {% if condition %}...{% endif %}
ptifel If/else statement {% if %}...{% else %}...{% endif %}
ptelif If/elif/else statement {% if %}...{% elif %}...{% else %}...{% endif %}
ptwith With statement {% with variable %}...{% endwith %}

πŸ”§ Jinja2-Specific Snippets

For Flask, FastAPI, and other Jinja2 projects

Prefix Description Output
ptj-url Static file URL {{ url_for('static', filename='file.css') }}
ptj-mac Macro definition {% macro name %}...{% endmacro %}
ptj-com Comment {# comment #}
ptj-set Set variable {% set var = value %}

🎨 Django-Specific Snippets

For Django projects

Prefix Description Output
ptd-url URL tag {% url 'view-name' args %}
ptd-load Load tag library {% load static %}
ptd-stat Static file {% static 'path/to/file' %}
ptd-inc Include template {% include 'template.html' %}
ptd-firstof First of variables {% firstof var1 var2 %}

πŸ’» Usage Examples

Creating a New Template

Type ptnew and press Tab:

{% extends 'base.html' %}

{% block content %}
  <!-- Your cursor starts here -->
{% endblock content %}

{% block scripts %}
{% endblock scripts %}

Adding a For Loop

Type ptfor and press Tab:

{% for item in items %}
  <!-- Your cursor starts here -->
{% endfor %}

Then tab through: item β†’ items β†’ loop body

Django Static File

Type ptd-stat and press Tab:

{% static 'css/style.css' %}

🀝 Contributing

Found a bug? Want a new snippet? Contributions are welcome!

  1. Report Issues: Open an issue
  2. Request Features: Have an idea? Share it!
  3. Submit PRs: Fork, code, and submit a pull request

Suggesting New Snippets

When requesting a new snippet, please include:

  • The template syntax you want added
  • Which framework it's for (Jinja2/Django/both)
  • A brief description of what it does

πŸ“ Release Notes

See GitHub Releases for the detailed version history and changelog.


πŸ’– Support This Project

This extension is free and open source. If you find it helpful, consider:


πŸ“œ License

MIT Β© Ricky White


πŸ™ Acknowledgments

Created and maintained by Ricky White

Special thanks to all contributors who have helped improve this extension!


Happy Coding! πŸŽ‰

Made with ❀️ for the Python community

Sponsor this project

  •  

Contributors 3

  •  
  •  
  •