开发者

Array merging/manipulation with Velocity

开发者 https://www.devze.com 2022-12-24 06:26 出处:网络
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.

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.


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)


I believe we can use any methods from here, such as add, addAll, remove or removeAll.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号