I have an array set inside a velocity template that contains some paths.
The idea is to put a few "default" .js/.css files that 90% of the pages will use in this array.
However, the other pages will still have to be able to add/delete values from this array, in case there are no linked files at all, or I need to add some.
Given this code:
#set ( $head.scripts = [ "https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" ] )
#foreach ($URI in $head.scripts)
<script type="text/javascript" src="$URI"></script>
#end
Is there any way to add/delete values from these defaults?
I have seen this list tool, but it looks like it's not enough for what I need.
Velocity is a Java-based templating engine. It's an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP. Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.
To merge elements from one array to another, we must first iterate(loop) through all the array elements. In the loop, we will retrieve each element from an array and insert(using the array push() method) to another array. Now, we can call the merge() function and pass two arrays as the arguments for merging.
Answer: Use the indexOf() Method You can use the indexOf() method in conjugation with the push() remove the duplicate values from an array or get all unique values from an array in JavaScript.
Example 1: Using concat() and for Loop In the above program, the two array elements are merged together and the duplicate elements are removed. Here, The two arrays are merged using the concat() method. The for...of loop is used to loop through all the elements of arr .
If this array is created in Velocity then it is backed by ArrayList class, so it supports all corresponding methods.
$head.scripts.add("new element")
$head.scripts.remove(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With