Can I suggest you use Generico (or Poodll ) for this?
You put your code in the Generico template.
You add a Generico tag to the html editor
When the Generico filter encounters the tag it will swap it out, for your code.
Some widget templates included in Generico / Poodll are here: