Snippet to automate version control not working

I know I tested this before and cannot figure out why this isn’t working now.

I have this snippet to automate the versioning of my css/js files in my head:
[[!AutoVersCtrl? &path=path/to/file &type=css]]

The AutoVersCtrl snippet:

<?php
if ( $type = 'css' ) : 
    echo '<link rel="stylesheet" href="' . $modx->runSnippet( 'auto_version', array( 'file' => "/".$path ) ) . '" type="text/css">';
elseif ( $type = 'js' ) : 
    echo '<script src="' . $modx->runSnippet( 'auto_version', array( 'file' => "/".$path ) ) . '" type="text/javascript"></script>';
endif;

The auto_version snippet:

if (strpos($file, '/') !== 0 || !file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) return $file;

// retrieving the file modification time
// https://www.php.net/manual/en/function.filemtime.php
$mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $file);

return sprintf("%s?v=%d", $file, $mtime);

Now for some reason, this works fine when the type is set to css. But when the type is set to js, it outputs it as if it was set to css.

I can’t figure out what i’m doing wrong.

Change if ( $type = 'css' ) : and elseif ( $type = 'js' )
to if ( $type == 'css' ) : and elseif ( $type == 'js' ).

1 Like

Excuse me while i go bang my head against the wall…

1 Like