The DMSTwigExtensionBundle

  • PHP
  • November 30, 2012

When I started using Symfony one of the aspects that really caught my eye was Twig, it really got me back into using a template engine and I don’t think i can ever go back to mixing my HTML and PHP again.

Twig’s extensibility is also something truly awesome and powerful when developing for Symfony, it allows me to easily whip up an extension that get information from the right place in the right way without having to pollute the controller with excessive interactions, or quickly provide a filter to hammer data into the format I need it to be in.

So I created the DMSTwigExtensionBundle to do two things: hold my custom extensions that I use in various projects and enable other extensions, like the non-core extensions written by Fabien Potencier.

Fabien distributes a few extensions which he deemed should not be in core, but are very useful, these are in his own repository and they do thinks like: truncate text, wordwrap, localized date formatting, amongst other things.

I usually have these enabled in my projects, but that means that every time I need to add the composer dependency and then pick one of my bundles to add the service calls with the “twig.extension” tag, which is a pain and out of place. With this bundle I can just drop it in and it will create all of those for me and even give me the option of turning them on or off via configuration, all in one single place.

As time goes i’ll be adding more useful extensions, either that I find or create myself, hopefully making it easy for you to just drop it into your project and start using them, but leaving it flexible enough that you can easily switch them on or off individually.

So check out the Repository at: https://github.com/rdohms/DMSTwigExtensionBundle Remember to open issues at the main DMS repository: https://github.com/rdohms/DMS

If you want to use it, just drop it into your composer file, more instructions in the README.

 { "require": { "dms/twig-extension-bundle": "1.\*" } } 
comments powered by Disqus

Related Posts

Estendendo o Smarty: TinyMCE

Estendendo o Smarty: TinyMCE

  • March 12, 2007

(Nota: sim estender não extender)

Uso, e recomendo, a utilização do Smarty em qualquer projeto PHP. Porque?

Bem tenho inúmeros motivos para fazer esta recomendação, mas neste post vou me limitar a apenas citar alguns, pois não é o objetivo.

  1. Separar PHP e HTML: código limpo, manutenção fácil
  2. Code e Layout em paralelo: agilidade no trabalho em equipe
  3. Funções de maquiagem: formatar data, wordwrap, funções que dizem respeito a visualização, ficam na visualização
  4. Funções customizadas: estender o Smarty é simples e útil

É neste ponto, o número 4 que vou focar este post, utilizando o tinyMCE como exemplo.

Read More
Rails: Segmentando CSS por telas

Rails: Segmentando CSS por telas

  • September 12, 2008

Sites muito grandes acabam por ter arquivos CSS enormes, e que mesmo divididos em várias partes e utilizando @import, são carregados em todas as páginas e podem causar atraso no carregamento de páginas.

Não seria ideal que, por exemplo, nossa página de login possua uma folha de estilo própria, mas que este CSS seja carregado apenas quando estivermos na página de login? Seria, e é isso que vou abordar neste artigo, um pequeno mas útil truque, que aprendi em um dos videocasts da Railscasts.com .

Read More
Como foi palestrar na Campus Party 2011

Como foi palestrar na Campus Party 2011

  • March 14, 2011

Este ano tive a oportunidade de voltar a Campus Party e mais uma vez palestrar na área de Desenvolvimento.

Read More