0

I have been wondering if it is possible to add a parameter for the asset twig function like this

#config.yml
...
framework:
   templating:
      parameters: 
         key: value
OR
twig:
   parameters:
      key: value
...

And in the twig file use asset like this

# twig file
<script src="{{ asset('/file/path', key) }}"></script>

And will regenerate

<script src="/file/path?key=value"></script>

I know i can create a macro to do this but i want to know if there are another way.

Thank for your reply

Particule42
  • 25
  • 1
  • 6
  • Did you figure this out? – codecowboy Oct 18 '12 at 08:50
  • Possible duplicate of [How to get config parameters in Symfony2 Twig Templates](https://stackoverflow.com/questions/6787895/how-to-get-config-parameters-in-symfony2-twig-templates) – Martijn Aug 29 '17 at 12:22

1 Answers1

0

Assets are generally static files and not dynamic scripts, are you sure you're doing the right thing? If you have an asset that accepts a parameter maybe it should be a in a controller with a route defined so you can act on it within code and a {{ path('...', {key: value}) }}

Otherwise, The only thing assetic lets you do is auto-append a version number to assets using assets_version

lifo
  • 2,791
  • 1
  • 25
  • 32