PHP code example of germania-kg / asset-timestamper

1. Go to this page and download the library: Download germania-kg/asset-timestamper 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/ */

    

germania-kg / asset-timestamper example snippets



use Germania\AssetTimestamper\AssetTimestamper;

// Instantiation
$at = new AssetTimestamper;

// Both are equal
echo $at( '/dist/styles.css' );
echo $at->__invoke( '/dist/styles.css' );

//even those, missing leading slash:
echo $at( 'dist/styles.css' );
echo $at->__invoke( 'dist/styles.css' );


// Outputs something like:
"/dist/styles/styles.20160522140459.css"


// Instantiation
$at = new AssetTimestamper( "/var/www/project/static" );

echo '<link rel="stylesheet" type="text/css" href="//static.test.com'
     . $at( '/dist/styles.css' ) . '">';

echo $twig->render("website.tpl", [
	'stylesheets' => [
		$at( 'dist/styles.css' ),
		$at( 'dist/widget.css' )
	]
]);


$at     = new AssetTimestamper( "/var/www/project/static" ),
$filter = new Twig_SimpleFilter('add_timestamp', $at),

$twig->addFilter( $filter );

echo $twig->render("website.tpl", [
	'stylesheets' => [
		'dist/styles.css',
		'dist/widget.css'
	]
]);