Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array merging/manipulation with Velocity

Tags:

velocity

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.

like image 850
Razor Avatar asked Mar 29 '10 11:03

Razor


People also ask

What is velocity .VM file?

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.

Can arrays be merged?

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.

How do you merge arrays of objects without duplicates in JavaScript?

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.

How do I merge two arrays in typescript without duplicates?

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 .


1 Answers

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)
like image 173
serg Avatar answered Oct 09 '22 12:10

serg