Jump to content

EPScript/Examples: Difference between revisions

From EPrints Documentation
m Reverted edit of JvgZ7x, changed back to last version by WikiSysop
 
→Testing a boolean field: Added advice for unset boolean fields
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{formats}}
{{EPScript}}
{{EPScript}}


= Examples =
= Examples =


Pluralising the editors of a book:
== Pluralising the editors of a book ==
<source lang="xml">
<if test="type = 'book' and is_set(editors)">
  <print expr="editors" />, (ed<if test="length(editors) gt 1">s</if>
</if>
</source>
 
== Rendering the URL of an EPrint ==
<source lang="xml">
<print expr="$config{base_url}" />/<print expr="eprintid" />/
</source>


{{codesample|
== Testing a boolean field ==
<pre>
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:
<if test="type = 'book' and is_set(editors)">
<source lang="xml">
  <print expr="editors" />, (ed<if test="length(editors) gt 1">s</if>
<if test="boolean_field = 'TRUE'">
</if>
  ...
</pre>
</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>
</source>

Latest revision as of 16:05, 12 May 2026


EPScript

Examples[edit]

Pluralising the editors of a book[edit]

 <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[edit]

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

Testing a boolean field[edit]

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>