We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Set script tag id using assets?

I'm trying to implement some fancy (frontend) framework where the developer decided to make the whole bloody thing dependant on the javscript tag having a specific id (WTF!?). This make me have to bend Phalcon to allow me to somehow pass in parameters in my assets management routines, like:

$this->assets->addJs( "path/to/file.js", array( "id" => "unique-js-id") ); or $this->assets->addJs( "path/to/file.js", { "id" : "unique-js-id"} );

Can this be done in some »standard« way?



8.7k

I'd replace the js file with a PHP one, and send the js file over it, especially if its content is diffirent according to the id.

I found your question when searching how to do this, so I had to find out myself :

$this->assets->addJs( "path/to/file.js", true, false,  array( "id" => "unique-js-id") );
{% for resource in assets.collection('footer') %}
   {{ javascript_include( [ 'src' : resource.getPath(), 'type' : 'text/javascript', 'id' : resource.getAttributes()['id']  ]  )  }}
{% endfor %}