Closed (fixed)
Project:
Subscriptions
Version:
6.x-1.x-dev
Component:
Documentation
Priority:
Minor
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
7 Dec 2008 at 19:09 UTC
Updated:
22 Dec 2008 at 00:26 UTC
In the default templates there are conditions like !sender_name==!sender_name. What is their meaning? Why do they not always return true?
Comments
Comment #1
salvisHere's the information from README.txt:
The left side of !sender_name==!sender_name is replaced, but the right side isn't. The condition is true only when the variable is not set.
This is how variable replacement works everywhere in Drupal, but it might be worth to add this bit here as a reminder.
Comment #2
gustav commentedThanks a lot for that prompt reply. I have added the following text to the help file at http://drupal.org/node/344021:
Note that only variable names that appear on the left-hand side of an equation are replaced and only if the variable is not empty. You can use a condition like !sender_name==!sender_name. The left side of !sender_name==!sender_name is replaced if the sender name is set, but the right side isn't. Therefore the condition is true only when the variable is not set.
Did I get that right?
Comment #3
salvisWhat help file are you referring to? The link points to this thread.
Since the syntax is
!varname==value, much of what you write is redundant."Not empty" is not the same as "not defined". A variable could be defined and empty, in which case
{{!varname==?...would be true.How about adding this to README.txt:
Comment #4
gustav commentedAh, I put the wrong link. The correct link to the help page is http://drupal.org/node/344030.
Thanks for making me aware of the distinction between empty and undefined variables. Unfortunately this will not help the end-user because they have no way of telling under which circumstances a variable will be empty and under which circumstances it will be undefined. Most of the theme templates decide on whether to print a particular element based on whether the corresponding variable is empty or not, rather than on whether it is defined or not. I think it would be better if the subscriptions module could follow that convention as well.
For the time being, how would you write a condition that tests for whether a variable is defined and non-empty?
Comment #5
salvisYou are right, there's no way to test that condition. But does that condition need testing?
We're not addressing the end user here but the administrator, and what we're doing is happening before theming. Take !sender_name, for example: it's either undefined or non-empty. Take !body: it's either empty or not, but never undefined (I think). For some fields I've provided predicates (helper variables that are either 0 or 1).
It will take some experimenting to get the templates just right, but I think we've covered all the bases.
The replacement algorithm is the one being used by t(), btw.
Comment #6
gustav commented!body is a good example. Consider an administrator who knows that they have some content types without a body field and who wants to write a node_tid template that can deal with this apropriately. How can we expect this administrator to know whether a content type without a body will have an empty body or an undefined body? You think it will be empty rather than undefined. But that is because you know a lot about the Drupal code, which the administrator can not be expected to do.
Rather than providing more explanations for the administrator about how each variable handles this issue of empty versus undefined, would it not be easy to change the substitution code so that it will substitute the empty string for variables that are either empty OR undefined? That, after all, is what Drupal does with the variables it passes to theme templates, so why not also do it for mail templates?
Comment #7
salvisI'm (still) not convinced. No one will get a template right with their first shot. It will always take some experimenting. I don't think this ought to be documented in more detail. Just let the administrator find out what works best for them.
We have three states: undefined, empty, and non-empty. Presently, we can test for
-- undefined (or not)
-- empty (or not)
but we cannot test for non-empty.
You're suggesting to treat undefined values as empty, but this would mean we lose information.
And it would mean we'd have to implement our own token replacement algorithm, which would remove every occurrence of an exclamation mark followed by any number of non-blank characters, unless it was matched by a variable.
Comment #8
gustav commentedSalvis, what you say about the admin just having to experiment sounds sensible. I agree with you that in practice that will probably work fine. Many thanks for all the thought you have put into this.
Comment #9
salvisOk, my pleasure — thanks for a good discussion!
Good night...