Associate Engine : "if/endif" statements  
Home > Associate Engine > Documentation > "if/endif" statements

"if/endif" Statements

Browse "if/endif" Statements
 

Related:



Introduction of "if/endif" Statements

Format template have the ability to interpret "IF" statements to determine whether or not to display certain fields. For example, a DVD includes fields such as the actors names, and the director's name. However, a BOOK, or MUSIC does not include those fields. In addition, you may wish to display 4 customer reviews, however, some records may only have 3 customer reviews available. Associate Engine is able to interpret "IF" statements to handle the differences in the different types of products.

The "IF" statement can be in either of the following two simple formats:

  1. {if CONDITION} TEXT {endif}
  2. <!--if CONDITION--> TEXT <!--endif-->

The TEXT can be any text or HTML that you want included when the CONDITION is true. Use the <!--if ...--> version (an HTML comment) if your HTML editor does not let you type arbitrary text where text is not allowed. For example, you might want to include a table row only if there is a list price, such as: (optional indentation is shown for clarity only)

<!--if details.listprice-->
    <TR><TD>List Price: {details.listprice}</TD></TR>
<!--endif-->

The <!--if details.listprice--> specifies the condition. The <!--endif--> specifies the end of the text. Everything in between is the text to include if the condition is true.

"if" statements can be nested, that is, TEXT can contain an "if" statement. The following includes a "List Price" row if there is a list price and includes a "You Save" row only if there is a list price and the savings (i.e.: difference between list price and sales price) is non-zero: (optional indentation is shown for clarity only)

<!--if details.listprice-->
    <TR><TD>List Price: {details.listprice}</TD></TR>
    <!--if details.yousave-->
        <TR><TD>You Save: {details.yousave}</TD></TR>
    <!--endif-->
<!--endif-->

The following examples using the "details" format template. (click here to see formatting source code for "details") Three examples listed below show the following:

  1. a DVD example (Harrison Ford movie);
  2. a MUSIC example (Faith Hill music CD)
  3. a BOOK example (John Gray book)

In each case, the general format of the <script> is as follows:

<script SRC="/cgi-bin/ae.pl?script&keyword=KEYWORD&type=search&mode=MODE&pagesize=1&format=details"></script>

The <script> tag uses the following parameters for KEYWORD and MODE:

EXAMPLE:   KEYWORD:   MODE:
DVD example   harrison+ford   dvd
MUSIC example   faith+hill   music
BOOK example   john+gray   books



DVD Example

DVD example using the "details" Format Template:

Notes: the following DVD example includes "Starring" and "Directed" fields. However, in the subsequent examples (music and book) these two fields are automatically excluded as they are not relevant to music and books. Also, the "Features" include 4 entries for this DVD (see also the music example where only 1 entry is available, and the book example where no Features are available).



Music Example

Music example using the "details" Format Template:

Notes: the following sample automatically excludes the "Starring" and "Directed" fields seen in the DVD example. The "Features" for this particular CD only has 1 entry at Amazon.com and as such the list has been automatically adjusted to show only bullet-point.



Book Example

BOOK example using the "details" Format Template:

Notes: the following sample automatically excludes the "Starring" and "Directed" fields seen in the DVD example. Also, since Amazon.com does not list any features for this book, the "if" statement excludes showing the "Features" title and bullet list as seen in the DVD and music examples above.





E.&O.E.; © Cusimano.Com Corporation; www.c3scripts.com