Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2009-10-03 09:32:11
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
bug (?) with if_different
Sometime the code
<txp:if_different>
<p class="datearticle"><txp:custom_field name="Affiche date" /></p>
</txp:if_different>
don’t work, at the first position in the list. (The first article in the list don’t display the custom_field content. If I remove the “If_different”, all is correct.)
I found the bug here :
In the sidebar (in the page,before the code above) I use this particular code (from txptips) :
<txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' category=''<txp:category />'' limit="1" />' />
<txp:if_variable name="has_articles" value="">
<txp:else /> ...
It seems that if_different check the first time with the custom_field value from the article_custom.
If I modify the sort attribute in the article_custom, all is OK … because I have more than 1 article in the list. But if I have 1 article … same value in custom field….
if_different must reset the field tested the first time we run in the loop …
Offline
Re: bug (?) with if_different
custom fields should not have spaces in their names. Try renaming the custom field to Affiche_date
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2009-10-03 10:25:29
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: bug (?) with if_different
from Textbook :
<p><txp:custom_field name="Book Author" />: <txp:custom_field name="Book Title" /><br />
Published by <txp:custom_field name="Book Publisher" /> in <txp:custom_field name="Book Year" />.</p>
EDIT : … but I try your suggestion : same problem.
Last edited by jpdupont (2009-10-03 10:29:44)
Offline
Re: bug (?) with if_different
If you use first code block (in the topic start) in multiple places in your templates/forms, then that probably explains what you’re seeing. The if_different tag uses its raw unparsed contents as an identifier for keeping track of which code you want to check for differences. So if you have multiple if_different tags that have the exact same contents (spaces and newlines are relevant as well), then TXP can’t keep those if_different tags apart. The solution is to vary the spacing or newlines a bit, which doesn’t have an effect on how the browser presents it to the visitor, but does make it different enough for if_different to keep the code blocks apart.
Offline
#5 2009-10-03 11:35:59
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: bug (?) with if_different
Ruud, thanks for the answer.
On my page (default template) I don’t have multiple if_different tags.
if_different is used once, in a txp:article loop, to display a date associated at the article, from a custom field.
The problem occurs only when the variable stuff (test if a category has articles by loading 1 article – I’m not in a if_different test !) load the same article as the first article in the main article list.
Offline
Re: bug (?) with if_different
When the article_custom tag (inside the variable tag) is parsed, it uses a form (‘default’, I assume) to parse the articles into a chunk of HTML which is then stored in the variable ‘has_articles’. If that’s the same form used for actually displaying the articles on the website, that would be exactly what I described in my first post (same if_different code used in two different contexts) . In that case you could probably solve it by doing this (using a different form for the article_custom tag in the sidebar or not using a form at all, since you don’t care about the article contents only that there are results at all):
<txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' category=''<txp:category />'' limit="1">Yay, articles!</txp:article_custom>' />
<txp:if_variable name="has_articles" value="">
<txp:else /> ...
Offline
#7 2009-10-03 13:12:59
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: bug (?) with if_different
Ok Ruud, I understand … and test with your code (using a different form for article_custom).
Now all is OK, and if_different works as expected !
Thanks !
Offline
#8 2009-10-03 13:56:22
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: bug (?) with if_different
jpdupont wrote:
from Textbook :
Thanks, Textbook example corrected.
Offline
Re: bug (?) with if_different
I think the Textbook example wasn’t wrong. You can use spaces in custom field names, but only if you use those names as attribute values in tags. What doesn’t work is using spaces in attribute names, which would happen if you tried to use a spaced custom field name for selecting articles in article/article_custom tags.
Offline
Re: bug (?) with if_different
ruud wrote:
What doesn’t work is using spaces in attribute names, which would happen if you tried to use a spaced custom field name for selecting articles in article/article_custom tags.
Isn’t this an inconsistency? disallowing spaces may result in a more uniform usage.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#11 2009-10-03 16:30:25
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: bug (?) with if_different
ruud wrote:
I think the Textbook example wasn’t wrong.
Not the way the custom field name was used there, no. But an example like that is confusing in my opinion, because using a name like that as an attribute will cause problems. And it’s kind of contradicting what it says earlier on that page:
Custom names may include letters (uppercase or lowercase), numbers and under_scores, but no spaces or other special characters.
Offline
Re: bug (?) with if_different
True, avoiding spaces is more consistent. For labels, being able to use spaces does look better on the write tab. I’ve used spaces in labels for custom fields without a problem. Then again, I’m not using them as attribute names.
I’ve said this before, but I think the labels shouldn’t be used in tags at all. Using the corresponding table column names would be a better. That also avoids conflicts between labels and column names.
Offline
Pages: 1