<div>
    <div piwik-widget
         containerid="{{ containerId|e('html_attr') }}"
         widgetized="{% if isWidgetized %}true{% else %}false{% endif %}"></div>

    <script type="text/javascript">
        $(function () {

            var piwikWidget = $('[piwik-widget][containerid={{ containerId|e('js') }}]');
            var isExportedAsWidget = $('body > .widget').size();

            if (!isExportedAsWidget) {
                angular.element(document).injector().invoke(function($compile) {
                    var scope = angular.element(piwikWidget).scope();
                    $compile(piwikWidget)(scope.$new());
                });
            }

        });
    </script>
</div>