How do I use Django templates without the rest of Django?

The solution is simple. It’s actually well documented, but not too easy to find. (I had to dig around — it didn’t come up when I tried a few different Google searches.) The following code works: >>> from django.template import Template, Context >>> from django.conf import settings >>> settings.configure() >>> t = Template(‘My name is … Read more

Truncate string in Laravel blade templates

In Laravel 4 & 5 (up to 5.7), you can use str_limit, which limits the number of characters in a string. While in Laravel 5.8 up, you can use the Str::limit helper. //For Laravel 4 to Laravel 5.5 {{ str_limit($string, $limit = 150, $end = ‘…’) }} //For Laravel 5.5 upwards {{ \Illuminate\Support\Str::limit($string, 150, $end=’…’) … Read more

How to use underscore.js as a template engine?

Everything you need to know about underscore template is here. Only 3 things to keep in mind: <% %> – to execute some code <%= %> – to print some value in template <%- %> – to print some values HTML escaped That’s all about it. Simple example: var tpl = _.template(“<h1>Some text: <%= foo … Read more