Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
IFs within forms within divs within IFs... not working! Help?
I want to show the content of some custom fields—up to three—if there are any—in a div within an article. If there is no content, I don’t want the div at all.
Here’s the relevant bit of my article form:
<div style="padding-top:10px;"><h3><txp:title /></h3>
</div>
<div class="snippet">
<txp:if_custom_field>
<div style="margin:2px 0;">
<txp:output_form form="Event_Info" />
</div>
</txp:if_custom_field>
<txp:body />
.......
and the above-mentioned “Event_Info” misc form:
<txp:if_custom_field name="Event_What">
<p class="eventinfo">WHAT <b><txp:custom_field name="Event_What"/></b></p>
</txp:if_custom_field>
<txp:if_custom_field name="Event_Where">
<p class="eventinfo">WHERE <b><txp:custom_field name="Event_What"/></b></p>
</txp:if_custom_field>
<txp:if_custom_field name="Event_When">
<p class="eventinfo">WHEN <b><txp:custom_field name="Event_When"/></b></p>
</txp:if_custom_field>
(Before I wanted the Event_Info feedback in a div, that code was within the article form in place of
<txp:if_custom_field>
<div style="margin:2px 0;">
<txp:output_form form="Event_Info" />
</div>
</txp:if_custom_field>
Which worked fine (apart from the ugly spacing).) Now, it returns nothing in the article. If this a case of there was an old IF who swallowed a form?
Thanks for looking out for us troublesome problem-bringers.
Chris.
Offline
#2 2009-06-03 19:47:14
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: IFs within forms within divs within IFs... not working! Help?
Make sure both the opening and closing div tags are either inside or outside the conditionals. (edit:) Only noticed after posting: you didn’t seem to close the <div class="snippet">
? Did you mean to do this:
<txp:if_custom_field>
<div class="snippet">
<div style="margin:2px 0;">
<txp:output_form form="Event_Info" />
</div>
</div>
</txp:if_custom_field>
Anyway, the output_form may be the problem. Why not replace that tag with the code from your Event_Info form?
Last edited by els (2009-06-03 19:58:30)
Offline
Re: IFs within forms within divs within IFs... not working! Help?
Els,
My “snippet” div was closed after the quoted code, after the body and some other bits.
I should have said, I’d already tried what you’ve suggested re: replacing that tag with the tagged form’s code before I tried putting the code into the separate form, but that didn’t work either.
What I get back in the article is all good—title, body, article_image and various other tags—I just get nothing from the <txp:if_custom_field>....
. Can you have two of the same conditionals, the inner more specific, nested like that?
Offline
Re: IFs within forms within divs within IFs... not working! Help?
Reading this it would appear I can’t nest them, only bump them up side-by-side with closings, or with else/s.
?
Offline
#5 2009-06-03 22:13:38
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: IFs within forms within divs within IFs... not working! Help?
No, it’s certainly possible to use them as you did, I think the use of <txp:if_custom_field>
without the name
attribute is the problem. Does this work?
<txp:variable name="anycustomfield" value='<txp:custom_field name="Event_What" /><txp:custom_field name="Event_Where" /><txp:custom_field name="Event_When" />' />
<txp:if_variable name="anycustomfield" value="">
<txp:else />
<div style="margin:2px 0;">
</txp:if_variable>
<txp:if_custom_field name="Event_What">
<p class="eventinfo">WHAT <b><txp:custom_field name="Event_What"/></b></p>
</txp:if_custom_field>
<txp:if_custom_field name="Event_Where">
<p class="eventinfo">WHERE <b><txp:custom_field name="Event_Where"/></b></p>
</txp:if_custom_field>
<txp:if_custom_field name="Event_When">
<p class="eventinfo">WHEN <b><txp:custom_field name="Event_When"/></b></p>
</txp:if_custom_field>
<txp:if_variable name="anycustomfield" value="">
<txp:else />
</div>
</txp:if_variable>
Offline
Re: IFs within forms within divs within IFs... not working! Help?
That works a treat. I’m surprised this turned out to be in need of such a work-around. Then again, I am a lot of trouble.
Thanks, Els.
chris/hicks
Offline