Results 1 to 4 of 4
  1. #1
    ABW Ambassador CrazyGuy's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,463
    Dyse Bugette?
    If you include an "if field_name" construct in a template, and the field doesn't exist in that datafeed, it throws an error.

    This means (for example) that templates have to be changed for feeds with and without retail prices whereas it would be much better to have one set of templates that include "ifs" to cater for differences.

    display the selling price
    if there's a retail price ... display the retail price
    if there's a manuf_name ... display the manuf_name

    etc
    etc

  2. #2
    ABW Ambassador cusimano's Avatar
    Join Date
    January 18th, 2005
    Location
    Toronto, Canada
    Posts
    1,369
    In a DySE template you can test to see if a variable is defined using ? before the variable name. The syntax is:

    <!--if ?NAME-->
    some stuff to show here
    <!--endif-->

    And you can nest "if" statements so you can do more complex stuff like:

    <!--if ?item.price-->
    <!--if item.price < 10-->
    Price: <!--item.price--> (under $10!!!)
    <!--endif-->
    <!--endif-->

    (each "if" requires an "endif") The first "if" tests to see if the item.price variable exists. The second "if" tests to see if the item.price is under 10.

    And you can reverse the conditional test by using !? (not defined):

    <!--if !?item.price-->
    Price: unknown
    <!--endif-->

    In the next release of view.pl, I'll update the default templates to check if all variables are defined before they are referenced.

    See also: Template Directives > if

    Yours truly,
    Cusimano.Com Corporation
    per: David Cusimano

  3. #3
    ABW Ambassador CrazyGuy's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,463
    Thanks - that's useful clarification and extra detail. I had interpreted the test for "defined" as meaning the variable had a value in this record, not using it to test if the variable existed at all.

    As you say - good practice then is going to be to test defined before using.

  4. #4
    ABW Ambassador cusimano's Avatar
    Join Date
    January 18th, 2005
    Location
    Toronto, Canada
    Posts
    1,369
    Testing to see if a variable is defined is really only necessary if you're using a default template set (/cgi-bin/dyse/default/templates/*.html) that are to be used for several DySE stores on your website. The default template set is used if a merchant specific template set is not found (/cgi-bin/dyse/MERCHANT/templates/*.html).

    The template sets that come with each merchant module are customized for that particular merchant module. For example, if a merchant doesn't supply prices, then I would have removed price from that merchant's template sets.

    Note: An empty value in a defined field is *not* the same as the field not being defined. To test for a non-empty/non-zero value use <!--if NAME--> and to test for a defined variable (with any value, even empty/zero) use <!--if ?NAME--> For further information, see if statements.

    Yours truly,
    Cusimano.Com Corporation
    per: David Cusimano

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. AE Script and DYSE
    By reaper in forum Cusimano.com Scripts
    Replies: 5
    Last Post: February 7th, 2006, 12:26 AM
  2. Dyse Allposters?
    By reaper in forum Cusimano.com Scripts
    Replies: 1
    Last Post: July 26th, 2005, 04:57 PM
  3. New Dyse with sitemap, not...
    By mmcbee in forum Cusimano.com Scripts
    Replies: 5
    Last Post: July 14th, 2005, 05:33 PM
  4. DySE::Calendars
    By bhey in forum Cusimano.com Scripts
    Replies: 2
    Last Post: July 3rd, 2005, 08:30 AM
  5. DYSE Formating
    By mmcbee in forum Cusimano.com Scripts
    Replies: 6
    Last Post: May 5th, 2005, 05:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •