show some data in koha ILS authority normal view - perl

in opac-authoritiesdetail.pl
i add
$template->param( "tag_781_z" => $record->subfield('781','z') );
and in opac-auth-detail.tt
[% IF( tag_781_z ) %]
<span class="">
<span class="label">Geographic Subdivision
</span>
[% tag_781_z %]
</span>
[% END %]
the result
the first value only shown
but I add 3 value

If field 780$z is repeatable you must add value this field to array.
Regards

Related

How to pass arguments to a subroutine in template toolkit function

I my document foo.tt i would like to write something like this:
[% INCLUDE header('str', 1, 2, 3, 5, 10) %]
My aim is to do some string manipulation on str and then with foreach / for iterates over all the numbers.
unfortunately i was unable to find that this type of syntax in Template toolkit is allowed.
What is Template toolkit way for passing arguments to a subroutine?
Any ideas how to do it?
You can pass arguments, but you need to give them names. Example:
outer.tt2:
[% INCLUDE header.tt2 header_string="str", items=[ 1, 2, 3, 5, 10 ] -%]
header.tt2:
String: [% header_string %]
[% FOREACH item IN items -%]
Item: [% item %]
[% END -%]
output:
String: str
Item: 1
Item: 2
Item: 3
Item: 5
Item: 10
Check out MACRO definitions:
[% MACRO header(str, items) BLOCK -%]
[% FOREACH i IN items; -%]
... your item code here ...
[% END -%]
[% END -%]
[% header('str',[1, 2, 3, 5, 10]) %]
If TT exposed the raw arguments list at the template level, you could call it as you indicated (e.g. header('str', 1, 2, 3, 5, 10)), but this is pretty close.

Using a variable to access hash keys in Template Toolkit

I have an array whose contents is
$VAR1 = {
'1' => 'May 05, 2011',
'0' => 'Jul 22, 2009',
'2' => 'Jun 13, 2012'
};
I am trying to display it in the catalyst template, the code is
[% x = 0 %]
[% FOREACH mortgage IN mortgages %]
<table width=40% border=1 cellspacing="0" cellpadding="10">
<tr>
<td>Date</td>
<td><b>[% dateformat.x %]</b></td>
</tr>
</table>
[% x = x+1 %]
[% END %]
The dateformat.x should display May 05, 2011 or Jul 22, 2009 or Jun 13, 2012 according to the value of x but the error is that it displays nothing. It shows a blank .
The error I think is that the key in the array is a string while the value of x that is used with the dateformat is numeric. If I add 0 or 1 with the dateformat then it displays correctly([% dateformat.0 %]).
[% dateformat.x %] looks in the dateformat hash for a key of x. To tell template toolkit that x is a variable, prefix it with $:
[% dateformat.$x %]
To access a hash entry using a key stored in another variable, prefix the key variable with '$' to have it interpolated before use (see Variable Interpolation).
I appreciate this question has already been asked and answered, but a handy alternative is the item() VMethod. This is particularly effective when you have hash keys that conflict with VMethods:
[%- SET myhash = { last => 'Blues', first => 'Elwood',
address => '1060 West Addison', city => 'Chicago' };
myhash.first; # doesn't do what you want,
# because first is a VMethod for 1st element in an array
myhash.item('first'); # displays "Elwood"
-%]
VMethods like first, last, size and sort are common traps for the unwary here.

Hash Dereference in Template Toolkit

I've got a multi-dimensional hash that I'm trying to print out in a table. I can't get the referencing / dereferencing right.
I'm putting an excel spreadsheet into the hash and I want to print out the corresponding rows and columns in html and match the rows/columns of the spreadsheet (some of which are empty).
I'm using Perl Dancer and Template Toolkit. On the server side the hash works fine. print $big_table{$column}{$row}; on the server side and it prints the correct column and row with NO issues.
On the client side, the 0, 1, 2... are supposed to be the columns. Some columns are blank so I can't just print the contents.
The way it is now it prints ARRAY(0x3e5389c). I tried a different way and it printed HASH...
I know I've got some reference/dereference issues. Any advice would be welcome.
Server Side Code:
my %big_table = ();
# $cell->value() is the text ripped from the excel cell at that location
$big_table{$column}{$row} = $cell->value();
template 'index', { big_table => \%big_table };
Client Side:
<Table border="3">
<% FOREACH n IN big_table.0 %>
<TR><TD>&nbsp<% big_table.0.keys %>&nbsp<TD>&nbsp<% big_table.1.keys %>
&nbsp<TD>&nbsp<% big_table.2.keys %>&nbsp<TD>&nbsp<% big_table.3.keys %>
&nbsp <TD>&nbsp<% big_table.4.keys %>
&nbsp<TD>&nbsp<% big_table.5.keys %>&nbsp
<% END %>
</Table>
Thanks in advance!
Got it working.
Changed to an array. '$big_table[$col][$row] = $cell->value();' and populated a second array with all the row #'s.
The Client looks like
<% FOREACH r IN row_numbers %>
<TR><TD> &nbsp <% big_table.0.$r %> &nbsp <TD> &nbsp <% big_table.1.$r %>...
<% END %>
Works great but it's probably crazy in-effecient :(. The spreadsheet is 800 rows long so it's a 2nd array with 800 elements just to iterate over 'FOREACH' loop.

How can I split and wrap HMENU items in TYPO3?

I'm trying to create a custom menu with TypoScript, I have 8 MenĂ¼ items an d I want to remove the css class "dropdown_1column and dropdown_1column" for the first 2 items and I do not know how?
I have experienced that it is with the Typoscript onSplit function possible,
whats wrong in this code?
wrap = <ul class="levels">|</ul>|| <ul class="levels">|</ul>|*|<div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>||<ul class="levels">|</ul>
The first two items should be wrapped in:
<ul class="levels">|</ul>
The remaining items should be wrapped in:
<div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
here ist my html output:
<li>
<a class="drop" href="blblbl/">item</a>
<div class="dropdown_1column">
<div class="col_1 firstcolumn">
<ul class="levels">
<li>
<li>
<li>
</ul>
</div>
</li>
and it must be so
<li>
<a class="drop" href="blblbl/">item</a>
<div>
<div>
<ul class="levels">
<li>
<li>
<li>
</ul>
</div>
</li>
Thank You for Help.
I'd say that no one has read TSref here :)
What you need:
According to 4th rule of optionSplit 1:
"if the last part is absent, the middle value is repeated"
So the most elegant and shortest optionSplit syntax will be:
first || second |*| the_rest
In Typoscript code it will be something like:
<ul class="levels">|</ul> || <ul class="levels">|</ul> |*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
What you got:
The optionSplit you wrote has syntax like this:
F || S |*| M1 || M2
which produces menu like:
F S M1 M2 M1 M2 M1 M2....
because the (the last, or if absent) the middle part is repeated continuously after the first part.
For more about optionSplit.
You could either go fo optionSplit to format items based on their position or you could split the menu in two parts and use begin and maxItems to define the range of items to use.
The latter is less sophisticated but should serve you well:
10 = COA
10 {
10 = HMENU
10 {
# your menu definition here
maxItems = 2
wrap = <ul class="levels">|</ul>
}
20 = HMENU
20 {
# your menu definition here
begin = 3
wrap = <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
}
}
Your option split syntax is wrong. It must be first |*| middle |*| last. Elements are filed in beginning from last. You can further split each property by a double pipe (||).
first || second |*| middle |*| second last || last
Thus it should be
wrap = <ul class="levels">|</ul>|| <ul class="levels">|</ul>|*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div> |*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
which has the format
first || second |*| middle |*| last
whereas the middle and the last part share the same code

sed/awk Capitallize everything between patterns and lowercase small words

I did find a way to capitalize the whole document, with both sed and awk, but how to do it, if I want to convert everything inside patterns from CAPS LOCK to Capital?
For example, I have an HTML file, and everything (multiple occurrences) between <b> and </b> has to be converted from TITLE to Title, and if possible making small words (1 ~ 2 letters) in lowercase.
From This:
<div id="1">
<div class="p"><b>THIS IS A RANDOM TITLE</b></div>
<table class="hugetable">
...
</table>
<div class="p"><b>THIS IS ANOTHER RANDOM TITLE</b></div>
<table class="hugetable">
...
</table>
...
</div>
To this:
<div id="1">
<div class="p"><b>This is a Random Title</b></div>
<table class="hugetable">
...
</table>
<div class="p"><b>This is Another Random Title</b></div>
<table class="hugetable">
...
</table>
...
</div>
This is not the most beautiful solution but I think it works:
sed -r -e '/<b>/ {s/( .)([^ ]*)/\1\L\2/g}' -e 's/<b>(.)/<b>\u\1/' -e '/<b>/ {s/(\b.{1,2}\b)/\L\1/g}' data
Explanation:
1st expression (-e): If a line contains <b>:
Then for each word which has a space in front of it, keep the space and the first (already capitalized) character (\1) and then convert all the following characters of the word to lower case (\L\2)
2nd expression (-e): The first word after <b> is still uncapitalized, so select the first character after the bold tag <b>(.) and replace it uppercased <b>\u\1
3rd expression (-e): Again if a line contains <b>:
Then select words of 1 or 2 characters in length \b.{1,2}\b and replace them lowercased \L\1