PHP code example of mouf / html.utils.weblibrarymanager

1. Go to this page and download the library: Download mouf/html.utils.weblibrarymanager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mouf / html.utils.weblibrarymanager example snippets


class MyController {
	/**
	 * @var $template TemplateInterface
	 */
	protected $template;

	...

	public function myAction() {
		$webLibraryManager = $this->template->getWebLibraryManager();
		...
	}
}

// Import a JS file from your project
// The file is relative to your ROOT_URL
$webLibraryManager->addJsFile('src/javascript/myJsFile.js');

// Import a JS file from a CDN
$webLibraryManager->addJsFile('https://code.jquery.com/jquery-2.1.1.min.js');

// Import a CSS file from your project
// The file is relative to your ROOT_URL
$webLibraryManager->addCssFile('src/css/myStyle.css');

$webLibraryManager->addAdditionalScript('<script>alert("Hello world!")</script>');

$webLibrary = new WebLibrary(
	["javascript/file1.js", "javascript/file2.js"],
	["css/style1.css", "css/style2.css"]);

$webLibraryManager->addLibrary($webLibrary);

$webLibraryManager->toHtml();

use TheCodingMachine\Funky\ServiceProvider;

class MyWebLibraryServiceProvider extends ServiceProvider {
    /**
     * @Factory(name="myWebLibrary", tags={@Tag(name="webLibraries")})
     */
    public static function createWebLibrary(ContainerInterface $container): WebLibrary
    {
        return new WebLibrary(['foo/bar.js', 'http://exemple.com/foo.js'],
            ['foo/bar.css', 'http://exemple.com/foo.css'], $container->get('root_url'));
    }
};