Lord Yggdrasill;11016331 wrote:umm you can construct html header in controller method like $response->addScript()? I am a bit confused, would you mind showing a rough example of how you are supposed to write in $response->addScript()? Thx.
It would depend very much on how you currently parse your template, but an example might be:
<?php
class HTMLpage{
private $scripts;
public function addScript( $root_relative_url ){
// don't add scripts twice
if( !in_array( $url,$this->scripts ) ){
// add script url to list
// you might add some sort of validation here,
// make sure the file exists, etc.
$this->scripts[] = $url;
}
}
public function printScriptsHere(){
// loop through script urls
foreach( $this->scripts as $script ){
// print each neatly in a script tag
print '<script src="'.$script.'"></script>'."\n";
}
}
}
your controller would request scripts as needed
$HTMLpage->addScript( '/path/to/my/script.js' );
and your template might look like this:
<!doctype html>
<html>
<head>
<title>Admin Contrl Panel</title>
<?php $HTMLpage->printScriptsHere(); ?>
</head>
<!-- . . . -->
however, note that you still need to know the root-relative path (or be able to determine it programatically) to the script in order to make this work. Once you know that, you can follow Ashley Sheridan's example (which is a simple, straightforward solution, and perfectly workable if you don't have any need for dynamically adding scripts).
[EDIT]
Lord Yggdrasill;11016361 wrote:my url contains a script path part that is stored in config file, the url looks like this:
http://www.domain.com/scriptpath/templates/acp/css/acp-style.css
So now if I hard code this url into linkrel, it will work nicely:
<link rel="stylesheet" href="/scriptpath/templates/acp/css/acp-style.css" type="text/css" />
But this code below does not work:
<link rel="stylesheet" href="<?php echo SCRIPTPATH;?>/templates/acp/css/acp-style.css" type="text/css" />
Do you know why this is happening?
What does it output when you use the code from your last example?
if the value of SCRIPTPATH is [font=monospace]/scriptpath[/font], then it should work just fine.