Skip to content

Instantly share code, notes, and snippets.

@mhulse
Last active December 21, 2015 00:59
Show Gist options
  • Save mhulse/6223956 to your computer and use it in GitHub Desktop.
Save mhulse/6223956 to your computer and use it in GitHub Desktop.
Caché example of how to trick the compiler into allowing CSP tags inside a (Javascript) tag/block.

Sometimes it's necessary to put CSP tags inside JS tags, like:

#[ new test set test = "BLAH" ]#

<script>
	
	var foo = "Hello world";
	
	<csp:if condition='test="BLAH"'>
		
		var billy = "#(test)#";
		
	</csp:if>
	
</script>

#[ kill test ]#

... Unfortunately, that's not gonna work. Here's the output:

<script>
	
	var foo = "Hello world";
	
	<csp:if condition='test="BLAH"'>
		
		var billy = "BLAH";
		
	</csp:if>
	
</script>

By tricking the compiler (using #("<")#), we can get it to work:

#[ new test set test = "BLAH" ]#

#("<")#script>
	
	var foo = "Hello world";
	
	<csp:if condition='test="BLAH"'>
		
		var billy = "#(test)#";
		console.log(billy);
	
	<csp:else>
		
		console.log('It didn\' work none. :(');
		
	</csp:if>
	
</script>

#[ kill test ]#

... and here's the output:

<script>
	
	var foo = "Hello world";
	
	
		
		var billy = "BLAH";
		console.log(billy);
	
	
	
</script>

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment