Webiny\Component\Bootstrap\ApplicationClasses\View::appendScript PHP 메소드

appendScript() 공개 메소드

Append a script to the script array.
public appendScript ( string $path, string $type = 'text/javascript' )
$path string Path to the script. It can be relative path to the Public/static folder or a full http path.
$type string Script type, default is 'text/javascript'.
    public function appendScript($path, $type = 'text/javascript')
    {
        $this->scripts[] = ['path' => $path, 'type' => $type];
        return $this;
    }

Usage 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());
 }