Webiny\Component\Bootstrap\ApplicationClasses\View::getScriptsHtml PHP Method

getScriptsHtml() public method

Get the script list as html tags.
public getScriptsHtml ( ) : string
return string
    public function getScriptsHtml()
    {
        $scripts = '';
        if (!isset($this->scripts)) {
            return $scripts;
        }
        foreach ($this->scripts as $s) {
            $scripts .= '<script type="' . $s['type'] . '" src="' . $s['path'] . '"></script>' . "\n";
        }
        return $scripts;
    }

Usage Example

Example #1
0
 public function testScripts()
 {
     $view = new View();
     $scriptOne = 'scriptOne.js';
     $scriptTwo = 'scriptTwo.js';
     $scriptThree = 'scriptThree.js';
     $view->appendScript($scriptOne);
     $view->prependScript($scriptTwo);
     $view->appendScript($scriptThree);
     $scriptArray = $view->getScripts();
     $expectedArray = [['path' => $scriptTwo, 'type' => 'text/javascript'], ['path' => $scriptOne, 'type' => 'text/javascript'], ['path' => $scriptThree, 'type' => 'text/javascript']];
     $this->assertSame($expectedArray, $scriptArray);
     $html = '';
     foreach ($expectedArray as $s) {
         $html .= '<script type="' . $s['type'] . '" src="' . $s['path'] . '"></script>' . "\n";
     }
     $this->assertSame($html, $view->getScriptsHtml());
 }