|
1 | | -# Python Template Snippets |
| 1 | +<div align="center"> |
| 2 | + <img src="logo.png" alt="Python Template Snippets Logo" width="200"/> |
| 3 | + |
| 4 | + # Python Template Snippets |
2 | 5 |
|
3 | | -This VS Code snippet extension includes snippets for both the Jinja2 and Django template engines. |
| 6 | + ✨ **Supercharge your template development workflow** ✨ |
4 | 7 |
|
5 | | -Quickly add snippets to HTML template files in your project. |
| 8 | + A comprehensive VS Code snippet collection for **Jinja2** and **Django** template engines. |
6 | 9 |
|
7 | | -If there is a snippet that is not included in this extension, please open an issue on the [repo here](https://github.com/EndlessTrax/python-template-snippets). |
| 10 | + [](https://github.com/EndlessTrax/python-template-snippets) |
| 11 | + [](https://marketplace.visualstudio.com/items?itemName=RickyWhite.python-template-snippets) |
| 12 | + [](LICENSE) |
8 | 13 |
|
9 | | -## Setup |
| 14 | +</div> |
10 | 15 |
|
11 | | -Just hit install! |
| 16 | +--- |
| 17 | + |
| 18 | +## 🚀 Why Use This Extension? |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | +**Stop typing this:** |
| 23 | +```html |
| 24 | +{% for item in items %} |
| 25 | + <!-- your code --> |
| 26 | +{% endfor %} |
| 27 | +``` |
| 28 | + |
| 29 | +**Start typing this:** |
| 30 | +``` |
| 31 | +ptfor → Tab → Fill in the blanks! |
| 32 | +``` |
| 33 | + |
| 34 | +### ✨ Features |
| 35 | + |
| 36 | +- 🎯 **20+ carefully crafted snippets** for Jinja2 and Django |
| 37 | +- ⚡ **Lightning-fast** - Type `pt` prefix and let IntelliSense do the rest |
| 38 | +- 🎨 **Smart cursor positioning** - Jump to exactly where you need to type |
| 39 | +- 🔄 **Multi-cursor support** - Tab between placeholders seamlessly |
| 40 | +- 🛠️ **Framework-agnostic** - Works with Flask, Django, FastAPI, and any Python web framework |
| 41 | +- 📦 **Zero configuration** - Works out of the box |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## 📦 Installation |
| 46 | + |
| 47 | +### From VS Code Marketplace (Recommended) |
| 48 | + |
| 49 | +1. Open VS Code |
| 50 | +2. Press `Ctrl+P` / `Cmd+P` |
| 51 | +3. Type `ext install RickyWhite.python-template-snippets` |
| 52 | +4. Press Enter and reload VS Code |
| 53 | + |
| 54 | +### Manual Installation |
| 55 | + |
| 56 | +1. Download the latest `.vsix` from [Releases](https://github.com/EndlessTrax/python-template-snippets/releases) |
| 57 | +2. Open VS Code |
| 58 | +3. Go to Extensions (`Ctrl+Shift+X` / `Cmd+Shift+X`) |
| 59 | +4. Click the `...` menu → `Install from VSIX` |
| 60 | +5. Select the downloaded file |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 🎯 Quick Start |
| 65 | + |
| 66 | +1. Open any HTML file in VS Code |
| 67 | +2. Type `pt` to see available snippets |
| 68 | +3. Select a snippet from the IntelliSense menu (or type the full prefix) |
| 69 | +4. Press `Tab` to trigger the snippet |
| 70 | +5. Fill in the placeholders and press `Tab` to jump between them |
| 71 | + |
| 72 | +### 💡 Pro Tip |
| 73 | +Enable tab completion in your VS Code settings for the best experience: |
| 74 | +```json |
| 75 | +{ |
| 76 | + "editor.tabCompletion": "on" |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## 📚 Snippet Reference |
| 83 | + |
| 84 | +All snippets use the `pt` prefix (short for "Python Template"). Here's the complete reference: |
| 85 | + |
| 86 | +### 🌐 General Snippets |
| 87 | +*Works with both Jinja2 and Django* |
| 88 | + |
| 89 | +| Prefix | Description | Output | |
| 90 | +|--------|-------------|---------| |
| 91 | +| `ptnew` | New HTML template file | Complete template with extends and blocks | |
| 92 | +| `ptvar` | Template variable | `{{ variable }}` | |
| 93 | +| `ptfilt` | Variable with filter | `{{ variable \| filter }}` | |
| 94 | +| `ptcode` | Code block tag | `{% code %}` | |
| 95 | +| `ptblock` | Block tag | `{% block name %}...{% endblock %}` | |
| 96 | +| `ptext` | Extends tag | `{% extends 'base.html' %}` | |
| 97 | +| `ptsup` | Super function | `{{ super() }}` | |
| 98 | +| `ptfor` | For loop | `{% for item in items %}...{% endfor %}` | |
| 99 | +| `ptif` | If statement | `{% if condition %}...{% endif %}` | |
| 100 | +| `ptifel` | If/else statement | `{% if %}...{% else %}...{% endif %}` | |
| 101 | +| `ptelif` | If/elif/else statement | `{% if %}...{% elif %}...{% else %}...{% endif %}` | |
| 102 | +| `ptwith` | With statement | `{% with variable %}...{% endwith %}` | |
| 103 | + |
| 104 | +### 🔧 Jinja2-Specific Snippets |
| 105 | +*For Flask, FastAPI, and other Jinja2 projects* |
| 106 | + |
| 107 | +| Prefix | Description | Output | |
| 108 | +|--------|-------------|---------| |
| 109 | +| `ptj-url` | Static file URL | `{{ url_for('static', filename='file.css') }}` | |
| 110 | +| `ptj-mac` | Macro definition | `{% macro name %}...{% endmacro %}` | |
| 111 | +| `ptj-com` | Comment | `{# comment #}` | |
| 112 | +| `ptj-set` | Set variable | `{% set var = value %}` | |
| 113 | + |
| 114 | +### 🎨 Django-Specific Snippets |
| 115 | +*For Django projects* |
| 116 | + |
| 117 | +| Prefix | Description | Output | |
| 118 | +|--------|-------------|---------| |
| 119 | +| `ptd-url` | URL tag | `{% url 'view-name' args %}` | |
| 120 | +| `ptd-load` | Load tag library | `{% load static %}` | |
| 121 | +| `ptd-stat` | Static file | `{% static 'path/to/file' %}` | |
| 122 | +| `ptd-inc` | Include template | `{% include 'template.html' %}` | |
| 123 | +| `ptd-firstof` | First of variables | `{% firstof var1 var2 %}` | |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 💻 Usage Examples |
| 128 | + |
| 129 | +### Creating a New Template |
| 130 | + |
| 131 | +Type `ptnew` and press Tab: |
| 132 | + |
| 133 | +```html |
| 134 | +{% extends 'base.html' %} |
| 135 | + |
| 136 | +{% block content %} |
| 137 | + <!-- Your cursor starts here --> |
| 138 | +{% endblock content %} |
12 | 139 |
|
13 | | -If installing this extension directly from the repo, copy it into your local `<user home>/.vscode/extensions` folder and restart VS Code. |
| 140 | +{% block scripts %} |
| 141 | +{% endblock scripts %} |
| 142 | +``` |
14 | 143 |
|
15 | | -Works best with `editor.tabCompletion` enabled (`on`) in your VS Code `Settings`. |
| 144 | +### Adding a For Loop |
16 | 145 |
|
17 | | -## Usage |
| 146 | +Type `ptfor` and press Tab: |
18 | 147 |
|
19 | | -Simply type `pt` to start using any of the snippets. The full documentation is below. |
| 148 | +```html |
| 149 | +{% for item in items %} |
| 150 | + <!-- Your cursor starts here --> |
| 151 | +{% endfor %} |
| 152 | +``` |
20 | 153 |
|
21 | | -This extension works best with `editor.tabCompletion` enabled (`on`) in your VS Code `Settings`. |
| 154 | +Then tab through: `item` → `items` → loop body |
22 | 155 |
|
23 | | -## Changelog |
| 156 | +### Django Static File |
24 | 157 |
|
25 | | -The full changelog can be found [here](CHANGELOG.md). |
| 158 | +Type `ptd-stat` and press Tab: |
26 | 159 |
|
27 | | -## Documentation |
| 160 | +```html |
| 161 | +{% static 'css/style.css' %} |
| 162 | +``` |
28 | 163 |
|
29 | | -See the tables below for general, jinja, django snippets. The `*` denotes where the cursor will start so you can start typing your variables etc. straight the way without wasting key strokes! A `*2` denotes the second position upon hitting the `tab` key again. |
| 164 | +--- |
30 | 165 |
|
31 | | -### General Snippets |
| 166 | +## 🤝 Contributing |
32 | 167 |
|
33 | | -Prefix | Output |
34 | | --------|------- |
35 | | -ptnew | Creates a simple base template for any Jinja/Django HTML file |
36 | | -ptvar | {{ `*` }} |
37 | | -ptfilt | {{ `* | *2` }} |
38 | | -ptcode | {% `*` %} |
39 | | -ptblock | {% block `*` %} {% endblock `*` %} |
40 | | -ptext | {% extends ' `*` ' %} |
41 | | -ptsup | {{ `super()` }} |
42 | | -ptfor | Adds a `for` loop block |
43 | | -ptif | Adds an `if` statement block |
44 | | -ptifel | Adds an `if/else` statement block |
45 | | -ptelif | Adds an `if/elif/else` statement block |
46 | | -ptwith | Adds a `with` statement block |
| 168 | +Found a bug? Want a new snippet? Contributions are welcome! |
47 | 169 |
|
48 | | -### Jinja Specific Snippets |
| 170 | +1. **Report Issues**: [Open an issue](https://github.com/EndlessTrax/python-template-snippets/issues) |
| 171 | +2. **Request Features**: Have an idea? Share it! |
| 172 | +3. **Submit PRs**: Fork, code, and submit a pull request |
49 | 173 |
|
50 | | -Prefix | Output |
51 | | --------|------- |
52 | | -ptj-url | {{ url_for('static', filename=' `*` ') }} |
53 | | -ptj-mac | {% macro `*` %} {% endmacro %} |
54 | | -ptj-com | {# `*` #} |
55 | | -ptj-set | {% set `*` = `*2` %} |
| 174 | +### Suggesting New Snippets |
56 | 175 |
|
57 | | -### Django Specific Snippets |
| 176 | +When requesting a new snippet, please include: |
| 177 | +- The template syntax you want added |
| 178 | +- Which framework it's for (Jinja2/Django/both) |
| 179 | +- A brief description of what it does |
58 | 180 |
|
59 | | -Prefix | Output |
60 | | --------|------- |
61 | | -ptd-url | {% url ' `*` ' `*2` %} |
62 | | -ptd-load | {% load `*` %} |
63 | | -ptd-stat | {% static ' `*` ' %} |
64 | | -ptd-inc | {% include ' `*` ' %} |
65 | | -ptd-firstof | {% firstof `*` `*2` %} |
| 181 | +--- |
66 | 182 |
|
67 | | -## Release Notes |
| 183 | +## 📝 Changelog |
68 | 184 |
|
69 | | -See the [Changelog](https://github.com/EndlessTrax/python-template-snippets/blob/master/CHANGELOG.md) |
| 185 | +See [CHANGELOG.md](CHANGELOG.md) for a detailed version history. |
70 | 186 |
|
71 | 187 | --- |
72 | 188 |
|
73 | | -This snippet was authored by [Ricky White](https://twitter.com/endlesstrax), and is an open-source extension. Please help to improve this by [submitting issues here](https://github.com/EndlessTrax/python-template-snippets/issues). |
| 189 | +## 💖 Support This Project |
| 190 | + |
| 191 | +This extension is free and open source. If you find it helpful, consider: |
| 192 | + |
| 193 | +- ⭐ [Starring the repo](https://github.com/EndlessTrax/python-template-snippets) |
| 194 | +- 💰 [Sponsoring on GitHub](https://github.com/sponsors/EndlessTrax) |
| 195 | +- 🐦 [Sharing on social media](https://twitter.com/intent/tweet?text=Check%20out%20Python%20Template%20Snippets%20for%20VS%20Code!&url=https://github.com/EndlessTrax/python-template-snippets) |
| 196 | +- 📝 [Writing a review](https://marketplace.visualstudio.com/items?itemName=RickyWhite.python-template-snippets&ssr=false#review-details) |
| 197 | + |
| 198 | +--- |
| 199 | + |
| 200 | +## 📜 License |
| 201 | + |
| 202 | +MIT © [Ricky White](https://github.com/EndlessTrax) |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## 🙏 Acknowledgments |
| 207 | + |
| 208 | +Created and maintained by [Ricky White](https://twitter.com/endlesstrax) |
| 209 | + |
| 210 | +Special thanks to all [contributors](https://github.com/EndlessTrax/python-template-snippets/graphs/contributors) who have helped improve this extension! |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +<div align="center"> |
| 215 | + |
| 216 | +**Happy Coding! 🎉** |
74 | 217 |
|
75 | | -If you'd like to sponsor the developwment of this extension, please consider [sponsoring me on GitHub](https://github.com/sponsors/EndlessTrax) |
| 218 | +Made with ❤️ for the Python community |
76 | 219 |
|
77 | | -**Happy Coding!** |
| 220 | +</div> |
0 commit comments