Custom Symfony2 filter not triggering with custom twig tag
I suggest you to have a look to vendor/symfony/assetic-bundle/
files as it contains the {% javascripts %}
implementation.
From that bundle's Resources/config/templating_twig.yml
, they inject a service named @templating.name_parser
, it looks like that's just what you are looking for.
You can have a try in a controller to do:
var_dump( $this ->get('templating.name_parser') ->parse('@AcmeBundle/Resources/dart/AcmeMain/web/main.dart') ->getPath());
About the tag itself, you can heavily copy/paste from the assetic bundle. And get some explanations about custom tags over one of my previous answers, here.
I think there is a very simple solution for your problem, that removes the need for a new {% darts %}
tag.
In Assetic tags, you can specify an output
argument, that allows you to override the default output path (which is js/*.js
in case of the {% javascripts %}
tag). By setting output
to dart/*.dart
, you not only change the directory where the files will be stored, but also the file extension.
Example:
{% javascripts '@AcmeBundle/Resources/dart/AcmeMain/web/main.dart' filter="MyCustomFilter" output='dart/*.dart' %} <script type="application/dart" src="{{ asset_url }}"></script>{% endjavascripts %}
Will (in production environment) result in:
<script type="application/dart" src="/dart/0b13818.dart"></script>
This feature is described here in the Symfony documentation, although it does not mention the fact that you can change the extension.
I just ran a quick test in my Symfony application and it seems to be working perfectly.