Adding values to a hash in Template Toolkit
I have a hash whose keys I am iterating over in Template Toolkit. The example is below....
<SELECT NAME="SelectList_[% feed.num %]" ID="SelectList_[% feed.num %]" SIZE="5" style="width: 250px;" MULTIPLE>
[% FOREACH xvar = feed.xvars.keys %]
<OPTION VALUE="[% xvar %]">[% xvar %]</OPTION>
[% END %]
<OPTION VALUE="X_File_Name">X_File_Name</OPTION>
</SELECT>
What I need to do is to alphabetize this SELECT list (using sort, which I know how to do. Problem is that
<OPTION VALUE="X_File_Name">X_File_Name</OPTION>
line. I was hoping to just add that value "X_File_Name" to the feed.xvars hash. Something l开发者_如何学JAVAike this...
[% feed.xvars = { "X_File_Name" => "1" } %]
hoping that that would add the value to the hash (as opposed to obliterating it). No such luck. Looking in the Template Toolkit book and googling doesn't yield anything either. Anyone know how to do this?
After I asked this I figured it out.
[% appendval = { "X_File_Name" => "1" } %]
[% feed.xvars.import(appendval) %]
There's a far easier approach:
[% feed.xvars.X_File_name = 1 %]
You access individual elements in a TT hash using the dot syntax.
精彩评论