Results 1 to 4 of 4
May 24th, 2005, 08:57 AM #1Dyse 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
May 24th, 2005, 12:43 PM #2
In a DySE template you can test to see if a variable is defined using ? before the variable name. The syntax is:
some stuff to show here
And you can nest "if" statements so you can do more complex stuff like:
<!--if item.price < 10-->
Price: <!--item.price--> (under $10!!!)
(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):
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
per: David Cusimano
May 25th, 2005, 11:14 AM #3
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.
May 25th, 2005, 02:04 PM #4
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.
per: David Cusimano
By reaper in forum Cusimano.com ScriptsReplies: 5Last Post: February 7th, 2006, 12:26 AM
By reaper in forum Cusimano.com ScriptsReplies: 1Last Post: July 26th, 2005, 04:57 PM
By mmcbee in forum Cusimano.com ScriptsReplies: 5Last Post: July 14th, 2005, 05:33 PM
By bhey in forum Cusimano.com ScriptsReplies: 2Last Post: July 3rd, 2005, 08:30 AM
By mmcbee in forum Cusimano.com ScriptsReplies: 6Last Post: May 5th, 2005, 05:24 PM