Support of relative path when loading JavaScript files
Closed this issue · 3 comments
Hello,
In my projects I prefer to use loading the JavaScript files via PHP.
This is very good, but in my case, every report has a separate PHP file in separate directory.
In your script StiJavaScript.php you already have a variable which do partial solution to relative paths
It is called useRelativeUrls and if set to true you do like this
$root = $this->useRelativeUrls ? '' : '/';
$result .= "<script src=\"{$root}vendor/stimulsoft/$product/scripts/$name\" type=\"text/javascript\"></script>\n";
This assumes that the report php file should be placed in root project directory, which causes error when it is not here.
I suggest to add new property like relativePath and change the code like this
....
public $usePacked = false;
public $useRelativeUrls = true;
public $relativePath =""; // <-- here r=the new properrt
.....
foreach ($scripts as $name) {
$product = strpos($name, 'dashboards') > 0 ? 'dashboards-php' : 'reports-php';
$root = $this->useRelativeUrls ? $this->relativePath : '/'; // <----- here the fix
$result .= "<script src=\"{$root}vendor/stimulsoft/$product/scripts/$name\" type=\"text/javascript\"></script>\n";
}
And then I do
$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Viewer);
$js->relativePath ="../../../";
$js->renderHtml();
I hope you understand what I mean.
Of course there are better solutions, but I hope you will add this feature
Thank you.
Best Regards,
Tony
Thank you for the suggestion, the task has been added to the TODO list.
Hello,
The specified fix will be added in version 2024.2.2, your code is used without changes, it is a good solution to the problem.
Hello,
Thank you.