Difference between revisions of "Views.pl"
(→menus => fields) |
|||
Line 22: | Line 22: | ||
*''string'' enclosed by quotation marks (") or by apostrophes ('); | *''string'' enclosed by quotation marks (") or by apostrophes ('); | ||
*''array'' which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ]; or | *''array'' which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ]; or | ||
− | *''hash'' which is a list of attribute | + | *''hash'' which is a list of attribute => value pairs enclosed into curly brackets. |
Thus the browse views definition is an array of hashes. | Thus the browse views definition is an array of hashes. | ||
===Basic attributes=== | ===Basic attributes=== | ||
− | ====id (mandatory) | + | {| border="1" cellpadding="4" cellspacing="0" |
− | + | |- valign="top" | |
− | String, this is the ID by which you will refer to this view, and also the name of the top directory in <nowiki>http://yourrepo/view/</nowiki>. This is the value of the ''browse_link'' attribute in [[eprint_fields.pl]]. Example: | + | | id |
+ | | (mandatory) String, this is the ID by which you will refer to this view, and also the name of the top directory in <nowiki>http://yourrepo/view/</nowiki>. This is the value of the ''browse_link'' attribute in [[eprint_fields.pl]]. Example: | ||
id => 'divisions', | id => 'divisions', | ||
− | + | |- valign="top" | |
− | + | |fields | |
− | + | |(deprecated) This attribute describes the field(s) by which the view is built. It has been replaced by the more general [[#Options in menus|menus]] attribute. | |
− | This attribute describes the field(s) by which the view is built. It has been replaced by the more general [[#menus|menus]] attribute. | + | |- valign="top" |
− | + | |nolink | |
− | + | |When this is set to 1 by adding | |
− | |||
− | When this is set to 1 by adding | ||
nolink => 1, | nolink => 1, | ||
then this view won't appear in the outmost <nowiki>http://repoid/view/</nowiki> browse page. | then this view won't appear in the outmost <nowiki>http://repoid/view/</nowiki> browse page. | ||
+ | |- valign="top" | ||
+ | |template | ||
+ | |Define an alternate template for all pages in this view. The template page should be a proper xml file in the <tt>repoid/cfg/lang/<langid>/templates/</tt> directory. The best way is to copy the default.xml file and edit it according to taste. | ||
− | |||
− | |||
− | |||
template => 'view_template', | template => 'view_template', | ||
− | + | |- valign="top" | |
− | = | + | |variations |
− | + | |An array of strings describing different rendering of the items at the lowest level (the ''list''). See [[#Variations|variations]]. | |
− | Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds ago, it is regenerated. | + | |- valign="top" |
− | + | | max_menu_age | |
− | + | | Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds ago, it is regenerated. | |
− | + | |- valign="top" | |
− | Defaults to 86400 (one day in seconds). If the lists in this view were generated more than than many seconds ago, it is regenerated. | + | |max_list_age |
− | + | |Defaults to 86400 (one day in seconds). If the lists in this view were generated more than than many seconds ago, it is regenerated. | |
− | + | |- valign="top" | |
− | + | |allow_null | |
− | These define the default values of the same attributes in all [[#menus|menus]]. I.e, if not defined otherwise there, they take this as the default value in this view. | + | new_column_at |
− | + | hideempty | |
− | + | render_menu | |
− | + | |These define the default values of the same attributes in all [[#Options in menus|menus]]. I.e, if not defined otherwise there, they take this as the default value in this view. | |
− | = | + | |- valign="top" |
− | + | |order | |
− | An array of ''menu descriptions'' | + | |This defines how the items in the menu list (at the lowest level) are ordered. |
+ | |- valign="top" | ||
+ | |menus | ||
+ | |An array of ''[[#Options in menus|menu descriptions]]''. Each ''menu'' is a refinement of the previous ones, while the last in is a ''list'' rather than a menu. In each menu, as minimum, you should give the field(s) which are used to define that level. Thus a ''menus'' definition looks like | ||
menus => [ | menus => [ | ||
{ <first menu definition> }, | { <first menu definition> }, | ||
− | { <second menu | + | { <second level menu> }, |
− | { < | + | { <last level (list)> }, |
], | ], | ||
− | If there is only one menu definition, then the browse will be ''flat'', otherwise you'll get links to the next level. | + | If there is only one menu definition, then the browse will be ''flat'', otherwise you'll get links to the next level. The last level will be rendered as a ''list'', all others are rendered as ''menus''. |
+ | |} | ||
+ | |||
===Options in ''menus''=== | ===Options in ''menus''=== | ||
− | + | {|border="1" cellpadding="4" cellspacing="0" | |
− | ==== | + | |- valign="top" |
− | An array of field identifiers. Items in all fields are merged together. For example, to define a list of those those who are either authors or editors or both, use the definition | + | |fields |
+ | |An array of field identifiers. Items in all fields are merged together. For example, to define a list of those those who are either authors or editors or both, use the definition | ||
fields => [ "creators_id", "editors_id" ], | fields => [ "creators_id", "editors_id" ], | ||
Line 87: | Line 92: | ||
fields => [ "subjects" ], | fields => [ "subjects" ], | ||
+ | |||
+ | <div style="color: #662211; background-color:#ddffdc; border:1px solid black; padding:3px;">'''Important!''' All fields must have the same type - i.e. you cannot mix titles and authors, say.</div> | ||
You can also add extra rendering info to the field name, without the "render_" prefix. For example, to make a date have resolution year, you would write | You can also add extra rendering info to the field name, without the "render_" prefix. For example, to make a date have resolution year, you would write | ||
Line 92: | Line 99: | ||
fields => [ "date;res=year" ], | fields => [ "date;res=year" ], | ||
− | or, | + | or, ordering authors by their ''given'' names rather than by their family names: |
− | fields => [ "creators_name; | + | fields => [ "creators_name;order=gf" ], |
− | + | You can add ";quiet" to the field name to force non-existing values to appear as empty space rather than the ugly "UNDEFINED" (see the allow_null property below). You can find the available rendering properties of different fields in the [[Metadata]] section. | |
− | + | |- valign="top" | |
− | + | |allow_null | |
− | + | |The ''undefined'' value among the possible values of the fields does not show up in the generated view. To allow the undefined value to appear as well, set | |
− | |||
allow_null => 1, | allow_null => 1, | ||
− | + | Beware: the title of the undefined entries will be the ugly UNDEFINED. You might consider to use the ";quiet" rendering option for field names. | |
− | + | |- valign="top" | |
− | + | |hideempty | |
− | + | |If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries. Used only in menus, not at the lower level (list). | |
− | If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries. | ||
Example: | Example: | ||
hideempty => 1, | hideempty => 1, | ||
− | + | |- valign="top" | |
− | + | |reverse_order | |
− | + | |If set, then the ordering of items in this menu is reversed. Example: | |
− | If set, then the ordering of items in this menu is reversed. Example: | ||
reverse_order => 1, | reverse_order => 1, | ||
− | + | |- valign="top" | |
− | + | |mode | |
− | + | |Possible values: ''sections'' and ''default'' (default). When defined as ''sections'' then grouping can be defined by the following data: | |
− | Possible values: ''sections'' and ''default'' (default). When defined as ''sections'' then grouping can be defined by the following data: | ||
* ''grouping_function'' (group by first character if not defined) | * ''grouping_function'' (group by first character if not defined) | ||
* ''group_sorting_function'' (how to sort members of a group) | * ''group_sorting_function'' (how to sort members of a group) | ||
* ''group_range_function'' | * ''group_range_function'' | ||
* ''open_first_section'' the front page should show the first section | * ''open_first_section'' the front page should show the first section | ||
− | + | See below. | |
− | = | + | |- valign="top" |
− | + | |render_menu | |
− | The configuration parameter which renders this menu. This should be a string, and also you should define a routine with the same name. For example if you | + | |The configuration parameter which renders this menu. This should be a string, and also you should define a routine with the same name. For example if you write |
render_menu => 'render_view_menu_3col_boxes', | render_menu => 'render_view_menu_3col_boxes', | ||
Line 140: | Line 143: | ||
} | } | ||
See there for hints how to tweak your own routine. | See there for hints how to tweak your own routine. | ||
+ | |- valign="top" | ||
+ | |new_column_at | ||
+ | |Used in menus (not lists) and in default mode. This is an array of integers representing the number of items in a view list before another column is added. For example: | ||
− | + | [ 10 ] | |
− | + | The menu is rendered as a single column data if there are less than 11 entries, then there would be 2 columns. | |
− | + | [ 10, 20 ] | |
− | + | This would have one column if there were ten or less values, two columns if there are twenty or less, and three columns for all other cases. | |
− | + | [ 0, 0 ] | |
− | + | This would always have three columns. | |
− | + | Add one to the number of integers in the array and you get the maximum number of columns. The entries are evenly distributed in the columns. | |
− | + | |} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | ===Variations=== | |
− | + | Variations is an array of string, such as | |
− | [ | + | [ "creators_name;first_letter", |
+ | "type", | ||
+ | "DEFAULT", | ||
+ | ] | ||
− | + | The variation "DEFAULT" is the default one, it is always a good practice to include it in the list. If no variation is given, "DEFAULT" is used. | |
− | |||
− | |||
− | |||
− | |||
+ | A variation consists of a field name, followed by zero, one or more ''options''. An option is either a single attribute, or an attribute, an equal sign, and the value of the attribute. Thus | ||
+ | "creators_name;truncate=4;hideup" | ||
+ | sets the attribute value "truncate" to 4, and "hideup" to 1 (or true). | ||
The following options are available: | The following options are available: | ||
{| border="1" cellpadding="4" cellspacing="0" | {| border="1" cellpadding="4" cellspacing="0" | ||
+ | |- valign="top" | ||
|reverse | |reverse | ||
|Reverses the order in which the groupings are shown. Default is the ordervalue for that field (usually alphanumeric). Useful for dates as you may want the highest values first. | |Reverses the order in which the groupings are shown. Default is the ordervalue for that field (usually alphanumeric). Useful for dates as you may want the highest values first. | ||
− | |- | + | |- valign="top" |
|filename | |filename | ||
|Changes the filename of the view variation. The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed. | |Changes the filename of the view variation. The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed. | ||
filename=different_filename | filename=different_filename | ||
− | |- | + | |- valign="top" |
|first_value | |first_value | ||
|If a field is multiple, only use the first value. Otherwise each item will appear once for each value. | |If a field is multiple, only use the first value. Otherwise each item will appear once for each value. | ||
− | |- | + | |- valign="top" |
|first_initial | |first_initial | ||
|If using a name, truncate the given name to the first initial. This will make items like "Les Carr" and "Leslie Carr" appear together. Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win. | |If using a name, truncate the given name to the first initial. This will make items like "Les Carr" and "Leslie Carr" appear together. Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win. | ||
− | |- | + | |- valign="top" |
|first_letter | |first_letter | ||
|The same as 'truncate=1' | |The same as 'truncate=1' | ||
− | |- | + | |- valign="top" |
|truncate | |truncate | ||
|Use the first X characters of a value to group by. truncate=4 may be useful for dates as it will group by the first four digits (the year) only. | |Use the first X characters of a value to group by. truncate=4 may be useful for dates as it will group by the first four digits (the year) only. | ||
truncate=4 | truncate=4 | ||
− | |- | + | |- valign="top" |
|tags | |tags | ||
|Useful for fields like keywords where values may be separated by commas or semi-colons. The value is split on these two characters ( , and ; ) and a heading is created for each. | |Useful for fields like keywords where values may be separated by commas or semi-colons. The value is split on these two characters ( , and ; ) and a heading is created for each. | ||
− | |- | + | |- valign="top" |
|cloud | |cloud | ||
|Creates a tag cloud. Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use. | |Creates a tag cloud. Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use. | ||
− | |- | + | |- valign="top" |
|cloudmax | |cloudmax | ||
|The % size of the largest tag in a tag cloud. | |The % size of the largest tag in a tag cloud. | ||
− | |- | + | |- valign="top" |
|cloudmin | |cloudmin | ||
|The % size of the smallest tag in a tag cloud. | |The % size of the smallest tag in a tag cloud. | ||
− | |- | + | |- valign="top" |
|jump | |jump | ||
| | | | ||
Line 231: | Line 221: | ||
Turns of the 'jump to' text before the list of subheading navigation links. | Turns of the 'jump to' text before the list of subheading navigation links. | ||
− | |- | + | |- valign="top" |
|no_seperator (sic) | |no_seperator (sic) | ||
|Turns of the separator between each subheading navigation link (by default a vertical bar symbol). | |Turns of the separator between each subheading navigation link (by default a vertical bar symbol). | ||
− | |- | + | |- valign="top" |
|string | |string | ||
|Uses values 'as is'. No ordervalues, no phrases. | |Uses values 'as is'. No ordervalues, no phrases. | ||
− | |- | + | |- valign="top" |
|hideup (since 3.1.1) | |hideup (since 3.1.1) | ||
|Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files) | |Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files) | ||
− | |- | + | |- valign="top" |
|render_fn | |render_fn | ||
|Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl | |Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl | ||
|} | |} | ||
+ | |||
+ | ===Phrases=== | ||
+ | |||
+ | ===Standard=== | ||
+ | |||
+ | ====heading_level==== | ||
+ | |||
+ | ====include==== | ||
+ | |||
+ | ====subheadings==== | ||
+ | |||
+ | ===Extra feature=== | ||
+ | |||
+ | ====citation==== | ||
+ | |||
+ | ====nocount==== | ||
+ | |||
+ | ====nohtml==== | ||
+ | |||
+ | ====noindex==== | ||
+ | |||
+ | ====nolink==== |
Revision as of 16:18, 15 July 2009
Contents
Option avaible for the views config
This link is an 'How to' about views with examples.
The general form of views definition is
$c->{browse_views} = [ { <first browse definition> }, { <second browse definition> }, ... { <last browse definition> }, ];
(be careful about commas and semicolons). The order of the browse definitions determines the order in which these will appear in the http://repoid/view/ page.
Each browse definition is a collection of attributes, given as
attribute1 => value1, attribute2 => value2, ...
(again, the value should end by a comma). The value can be
- string enclosed by quotation marks (") or by apostrophes (');
- array which starts by a square bracket [ followed by the elements of the array (separated by commas) and closed by ]; or
- hash which is a list of attribute => value pairs enclosed into curly brackets.
Thus the browse views definition is an array of hashes.
Basic attributes
id | (mandatory) String, this is the ID by which you will refer to this view, and also the name of the top directory in http://yourrepo/view/. This is the value of the browse_link attribute in eprint_fields.pl. Example:
id => 'divisions', |
fields | (deprecated) This attribute describes the field(s) by which the view is built. It has been replaced by the more general menus attribute. |
nolink | When this is set to 1 by adding
nolink => 1, then this view won't appear in the outmost http://repoid/view/ browse page. |
template | Define an alternate template for all pages in this view. The template page should be a proper xml file in the repoid/cfg/lang/<langid>/templates/ directory. The best way is to copy the default.xml file and edit it according to taste.
template => 'view_template', |
variations | An array of strings describing different rendering of the items at the lowest level (the list). See variations. |
max_menu_age | Defaults to 86400 (one day in seconds). If the menus in this view has been generated more than that many seconds ago, it is regenerated. |
max_list_age | Defaults to 86400 (one day in seconds). If the lists in this view were generated more than than many seconds ago, it is regenerated. |
allow_null
new_column_at hideempty render_menu |
These define the default values of the same attributes in all menus. I.e, if not defined otherwise there, they take this as the default value in this view. |
order | This defines how the items in the menu list (at the lowest level) are ordered. |
menus | An array of menu descriptions. Each menu is a refinement of the previous ones, while the last in is a list rather than a menu. In each menu, as minimum, you should give the field(s) which are used to define that level. Thus a menus definition looks like
menus => [ { <first menu definition> }, { <second level menu> }, { <last level (list)> }, ], If there is only one menu definition, then the browse will be flat, otherwise you'll get links to the next level. The last level will be rendered as a list, all others are rendered as menus. |
fields | An array of field identifiers. Items in all fields are merged together. For example, to define a list of those those who are either authors or editors or both, use the definition
fields => [ "creators_id", "editors_id" ], Even if there is a single field, you must use square brackets, such as fields => [ "subjects" ], Important! All fields must have the same type - i.e. you cannot mix titles and authors, say.
You can also add extra rendering info to the field name, without the "render_" prefix. For example, to make a date have resolution year, you would write fields => [ "date;res=year" ], or, ordering authors by their given names rather than by their family names: fields => [ "creators_name;order=gf" ], You can add ";quiet" to the field name to force non-existing values to appear as empty space rather than the ugly "UNDEFINED" (see the allow_null property below). You can find the available rendering properties of different fields in the Metadata section. |
allow_null | The undefined value among the possible values of the fields does not show up in the generated view. To allow the undefined value to appear as well, set
allow_null => 1, Beware: the title of the undefined entries will be the ugly UNDEFINED. You might consider to use the ";quiet" rendering option for field names. |
hideempty | If a category is empty, don't show it as an entry. Default value: show all entries, even if they contain no entries. Used only in menus, not at the lower level (list).
Example: hideempty => 1, |
reverse_order | If set, then the ordering of items in this menu is reversed. Example:
reverse_order => 1, |
mode | Possible values: sections and default (default). When defined as sections then grouping can be defined by the following data:
See below. |
render_menu | The configuration parameter which renders this menu. This should be a string, and also you should define a routine with the same name. For example if you write
render_menu => 'render_view_menu_3col_boxes', then this menu will be rendered by the routine which is defined in views_render_menu_example.pl as $c->{render_view_menu_3col_boxes} = sub { ... } See there for hints how to tweak your own routine. |
new_column_at | Used in menus (not lists) and in default mode. This is an array of integers representing the number of items in a view list before another column is added. For example:
[ 10 ] The menu is rendered as a single column data if there are less than 11 entries, then there would be 2 columns. [ 10, 20 ] This would have one column if there were ten or less values, two columns if there are twenty or less, and three columns for all other cases. [ 0, 0 ] This would always have three columns. Add one to the number of integers in the array and you get the maximum number of columns. The entries are evenly distributed in the columns. |
Variations
Variations is an array of string, such as
[ "creators_name;first_letter", "type", "DEFAULT", ]
The variation "DEFAULT" is the default one, it is always a good practice to include it in the list. If no variation is given, "DEFAULT" is used.
A variation consists of a field name, followed by zero, one or more options. An option is either a single attribute, or an attribute, an equal sign, and the value of the attribute. Thus
"creators_name;truncate=4;hideup"
sets the attribute value "truncate" to 4, and "hideup" to 1 (or true).
The following options are available:
reverse | Reverses the order in which the groupings are shown. Default is the ordervalue for that field (usually alphanumeric). Useful for dates as you may want the highest values first. |
filename | Changes the filename of the view variation. The default is the name of the metadata field used, so if two variations use the same metadata field with different options, this is needed.
filename=different_filename |
first_value | If a field is multiple, only use the first value. Otherwise each item will appear once for each value. |
first_initial | If using a name, truncate the given name to the first initial. This will make items like "Les Carr" and "Leslie Carr" appear together. Note it will also make "John Smith" and "Jake Smith" appear together too, showing that you really never can win. |
first_letter | The same as 'truncate=1' |
truncate | Use the first X characters of a value to group by. truncate=4 may be useful for dates as it will group by the first four digits (the year) only.
truncate=4 |
tags | Useful for fields like keywords where values may be separated by commas or semi-colons. The value is split on these two characters ( , and ; ) and a heading is created for each. |
cloud | Creates a tag cloud. Sets jump to 'plain', cloudmax to 200, cloudmin to 80 and no_separator, then resizes the jump-to links according to frequency of use. |
cloudmax | The % size of the largest tag in a tag cloud. |
cloudmin | The % size of the smallest tag in a tag cloud. |
jump |
jump=plain Turns of the 'jump to' text before the list of subheading navigation links. |
no_seperator (sic) | Turns of the separator between each subheading navigation link (by default a vertical bar symbol). |
string | Uses values 'as is'. No ordervalues, no phrases. |
hideup (since 3.1.1) | Defaults to "0". If set to "1" this hides the "up to parent" link (often you want to hide this on .include files) |
render_fn | Name of a function to render this groupings list of items. For an example, see views_render_items_example.pl |