Exhibit/Conditional content

From SIMILE Widgets
Revision as of 01:04, 3 November 2015 by Tullyhansen (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Conditional content methods

The expression ex:if-exists is the simplest but most common way to access information in a database. An example from the tutorial:

<div ex:if-exists=".co-winner" class="co-winners">Co-winners: 
  <span ex:content=".co-winner"></span>

If a co-winner exists, the stored information is displayed. If not, the area remains empty. But the ex:if-exists attribute is not very powerful, because it has no "else" attribute.

There are a few ways to approach "else" conditions in Exhibit. Exhibit offers a "switch" element on properties. Here, the div stays empty if Class.offering is 'Currently Offered,' otherwise it displays the .offering status.

<div ex:select=".offering">
  <div ex:case="Currently Offered"></div>
  <div ex:content=".offering" class="no-offering"></div>

Though there doesn't exist an actual ex:else-exists attribute, there is simple if/else logic available, as shown in these two examples (you may or may not need curled braces, depending on where you're using this code).

<div ex:content="if(exists(.url), .url, 'no link')">
<div ex:content="{{ if( exists(.url), .url, concat('http://course.mit.edu', .id) ) }}">

There is also the ex:if attribute. An example:

<div ex:if="contains(.ResourceOwner, 'Other')">
  <span>ResourceOwner: <img src="image.jpg"/> 
    <span ex:content=".ResourceOwner">

Finally, to display more complex content conditionally, dynamic styles can be used to toggle the display of the correct div instead, similar to the technique used in Dynamic URLs.

<div ex:display-style-subcontent="{{ if(exists(!class-user-rating-of), 'block', 'none') }}">
  Your Rating: <span ex:content="!class-user-rating-of.rating"></span>
<div ex:display-style-subcontent="{{ if(not(exists(!class-user-rating-of)), 'block', 'none') }}">
  Rate this: (insert rating element here)

Note: Perhaps there is a correct way to do this. A snippet of code found in Picker's browse.html:

<span ex:if="contains(.has-final, 'true')">
  <span class="hasfinal"> +final</span>

Note: a useful regular expression to find examples of ex:___-(sub)content:

grep -R 'ex:[a-zA-Z]*\-\(sub\)*content' ./*.html

Personal tools