Skip to content

Instantly share code, notes, and snippets.

@ben-caplan
Created October 18, 2013 13:07
Show Gist options
  • Save ben-caplan/7041276 to your computer and use it in GitHub Desktop.
Save ben-caplan/7041276 to your computer and use it in GitHub Desktop.
Add script macro
#*
ADD SCRIPT MACRO
@use #addScript( $scriptPath )
*#
#set( $scriptArray = [] )##
#macro( addScript $src )##
## CHECK TO MAKE SURE THAT VARS HAVE BEEN SET
#if( $UtilMethods.isSet($src) )##
#set( $scriptInMap = 'false' )##
## LOOP THROUGH MAP TO SEE IF $SRC IS ALREADY IN THE LIST
#foreach( $i in $scriptArray )##
#if( $scriptArray[$i] == $src )##
#set( $scriptInMap = 'true' )##
<!-- The script $src has already been included... -->
#end##
#end##
## CHECK TO SEE IF NAME HAS ALREAD BEEN USED
#if( $scriptInMap == 'false' )##
$scriptArray.add($src)
#set($cachebuster = $webapi.getLiveFileAsset($webapi.getIdentifierByURI("${src}")).getModDate().getTime())##
<script type="text/javascript" href="${src}?${cachebuster}"></script>
#end##
#end##
#end##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment