private function newSampleContainer($name = null) { $container = Assets::container($name); $container->add([new Dmlogic\Assets\Script(['path' => 'file.js']), new Dmlogic\Assets\Style(['href' => 'file.css'])]); return $container; }
<head> <title>Assets sample</title> <?php // output header collection styles echo Assets::container('header')->styles(); ?> <?php // output header collection scripts echo Assets::container('header')->scripts(); ?> </head> <body> <h1>Assets test</h1> <p>View the source to see your asset code generated.</p> <?php // Add a new Asset to the footer collection after it's initial creation Assets::container('footer')->add(new Dmlogic\Assets\Script(['inline' => 'console.log("An inline script");'])); ?> <?php // output footer collection scripts echo Assets::container('footer')->scripts(); ?> </body> </html>
<?php // includes and namespace. You'd normally autoload this via Composer include '../Assets.php'; include '../StaticAsset.php'; include '../Script.php'; include '../Style.php'; use Dmlogic\Assets\Assets; // get our config - this will differ by environment $collections = (include 'config.php'); /** * Here we create our collections by picking assets from those available * Output order is the order added */ $defaultAssets = Assets::createContainer($collections['default']); // or do this // $homeAssets = Assets::createContainer( $collections['home'], 'home' ); ?> <html> <head> <title>Assets sample</title> <?php // output collection styles echo $defaultAssets->styles(); ?> </head> <body>