# HG changeset patch # User Steve Losh # Date 1310532944 14400 # Node ID 1e2c49f56c5961628f86889f97f32b72d26eec55 # Parent fb6ff76d6105c7971350c50f47f5bf7d6f47c31e Filetypes. diff -r fb6ff76d6105 -r 1e2c49f56c59 content/blog/2011/06/django-advice.html --- a/content/blog/2011/06/django-advice.html Thu Jun 30 13:34:56 2011 -0400 +++ b/content/blog/2011/06/django-advice.html Wed Jul 13 00:55:44 2011 -0400 @@ -860,7 +860,7 @@ A common pattern I see in Django templates looks like this: - :::text + :::django {% templatetag openblock %} if business.title {% templatetag closeblock %} {% templatetag openvariable %} business.title {% templatetag closevariable %} {% templatetag openblock %} else {% templatetag closeblock %} @@ -869,7 +869,7 @@ Here's a simpler way to do that: - :::text + :::django {% templatetag openblock %} firstof business.title business.short_title {% templatetag closeblock %} `firstof` will return the first non-Falsy item in its arguments. @@ -957,14 +957,14 @@ I've added a few mappings to my `.vimrc` to make it quick and easy to set the correct `filetype`: - :::text + :::vim nnoremap _dt :set ft=htmldjango nnoremap _pd :set ft=python.django I also have a few autocommands that set the filetype for me when I'm editing a file whose name "sounds like" a Django file: - :::text + :::vim au BufNewFile,BufRead admin.py setlocal filetype=python.django au BufNewFile,BufRead urls.py setlocal filetype=python.django au BufNewFile,BufRead models.py setlocal filetype=python.django @@ -1024,7 +1024,7 @@ By default Vim doesn't fold Javascript files, but you can add some basic, perfectly serviceable folding with these two lines in your .vimrc: - :::text + :::vim au FileType javascript setlocal foldmethod=marker au FileType javascript setlocal foldmarker={,} @@ -1038,12 +1038,12 @@ [Jinja]: http://jinja.pocoo.org/ - :::text + :::vim au BufNewFile,BufRead *.html setlocal filetype=htmldjango I also have some autocommands that tweak how a few specific files are handled: - :::text + :::vim au BufNewFile,BufRead urls.py setlocal nowrap au BufNewFile,BufRead settings.py normal! zR au BufNewFile,BufRead dashboard.py normal! zR