Difference between revisions of "EPScript/Examples"

From EPrints Documentation
Jump to: navigation, search
(Added formats template)
(Testing a boolean field: Added advice for unset boolean fields)
 
Line 18: Line 18:
  
 
== Testing a boolean field ==
 
== Testing a boolean field ==
Boolean fields can be <tt>TRUE</tt>, <tt>FALSE</tt> or <tt>NULL</tt>. Just doing a <code>test="boolean_field"</code> isn't enough. Use this:
+
Boolean fields can be <tt>TRUE</tt>, <tt>FALSE</tt> or an empty string, the last of which means neither the true or false option has been selected. Just doing a <code>test="boolean_field"</code> isn't enough. Use this:
 
<source lang="xml">
 
<source lang="xml">
 
  <if test="boolean_field = 'TRUE'">
 
  <if test="boolean_field = 'TRUE'">
 +
  ...
 +
</if>
 +
</source>
 +
If you want to test if neither a true or false option has been selected, you will need to use:
 +
<source lang="xml">
 +
<if test="boolean_field = ''">
 
   ...
 
   ...
 
  </if>
 
  </if>
 
</source>
 
</source>

Latest revision as of 16:05, 12 May 2026

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


XML Configuration: EPScript - Control Format (EPC) - Citation - Workflow - Phrase - Template - XPAGE (static pages)


EPScript

Examples

Pluralising the editors of a book

 <if test="type = 'book' and is_set(editors)">
   <print expr="editors" />, (ed<if test="length(editors) gt 1">s</if>
 </if>

Rendering the URL of an EPrint

 <print expr="$config{base_url}" />/<print expr="eprintid" />/

Testing a boolean field

Boolean fields can be TRUE, FALSE or an empty string, the last of which means neither the true or false option has been selected. Just doing a test="boolean_field" isn't enough. Use this:

 <if test="boolean_field = 'TRUE'">
   ...
 </if>

If you want to test if neither a true or false option has been selected, you will need to use:

 <if test="boolean_field = ''">
   ...
 </if>