Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to hide <hr> if there are no articles ... ?
What’s the most elegant way to hide the <hr> if there are no articles?
<txp:article_custom section="articles" category="berichten" form="single_nolink_important" sort="" wraptag="" class="" break="" limit="2" label="Ingekomen berichten" labeltag="h3" />
<hr>
Last edited by RedFox (2015-04-09 09:36:24)
Offline
#2 2015-04-09 10:51:12
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,319
Re: How to hide <hr> if there are no articles ... ?
Have you already tried break="hr"? Edit: I’m asking cause I can’t tell with certainty whether the hr is placed after the article or before. (Resolved itself and not well thought out.)
You can of course also put that hr inside your single_nolink_important form.
Last edited by uli (2015-04-09 11:11:04)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: How to hide <hr> if there are no articles ... ?
If you only want one hr after the two articles you can use a variable
<txp:variable name="hrv" value='<txp:article_custom section="articles" category="berichten" form="single_nolink_important" sort="" wraptag="" class="" break="" limit="2" label="Ingekomen berichten" labeltag="h3" />' />
<txp:if_variable name="hrv" value="">
<txp:hide>no articles</txp:hide>
<txp:else />
<txp:variable name="hrv" />
<hr>
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to hide <hr> if there are no articles ... ?
uli wrote #289824:
Have you already tried
break="hr"?
Yes, but strange enough that doesn’t work … it doesn’t render <hr>‘s … and there are no error notifications too … !?
BTW … it’s not precisely what I want. If there are 2 articles … I get a <hr> between article 1 and 2 … and I only want a <hr> after 1, 2, etc. articles. And no <hr> if there are none articles.
Offline
#5 2015-04-09 11:04:47
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,319
Re: How to hide <hr> if there are no articles ... ?
Joop, I’ve amended my first post. (But maybe you can also go with Yiannis’ solution.)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: How to hide <hr> if there are no articles ... ?
Off course … variable’s … pffff.
Last edited by RedFox (2015-04-09 11:12:25)
Offline
Re: How to hide <hr> if there are no articles ... ?
Whoops, I did not notice that there was a form there. You might not need the code I posted as it might be an overkill. Could you tell us what you have in that form?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to hide <hr> if there are no articles ... ?
<div class="article important">
<h1 class="entry-title"><txp:title /></h1>
<txp:body />
</div>
Offline
Re: How to hide <hr> if there are no articles ... ?
I guess that the variable will work as I cannot See a way to include it in the form so as to appear only once.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to hide <hr> if there are no articles ... ?
RedFox wrote #289823:
What’s the most elegant way to hide the <hr> if there are no articles?
How about wrapping the <hr> tag inside a txp:if_last_article tag in your form? Does that work?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: How to hide <hr> if there are no articles ... ?
Yiannis … did you perhaps made a typo in your first post … ;-)
Now it’s working … off course > tvdiever.nl … top sidebar.
Bloke … also nice … wait a moment please.
Last edited by RedFox (2015-04-09 11:46:11)
Offline
Re: How to hide <hr> if there are no articles ... ?
Bloke … it does the job too … after some tweaking:
HTML:
<txp:article_custom section="articles" category="berichten" form="single_nolink_important" sort="" wraptag="" class="" break="hr" limit="2" label="" labeltag="" />
Form:
<txp:if_last_article>
<h3>Ingekomen berichten</h3>
<div class="article important">
<h1 class="entry-title"><txp:title /></h1>
<txp:body />
</div>
<hr>
<txp:else />
<div class="article important">
<h1 class="entry-title"><txp:title /></h1>
<txp:body />
</div>
</txp:if_last_article>
Offline
Re: How to hide <hr> if there are no articles ... ?
Oké, thanks all. Shall we vote?
BTW … I’m always hesitant to ask such simple questions, but hé, I’m learning so much … :))
Last edited by RedFox (2015-04-09 11:57:53)
Offline
Re: How to hide <hr> if there are no articles ... ?
I guess that Oleg is needed here to tell us which one uses less memory or even suggest an even more economic solution:)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to hide <hr> if there are no articles ... ?
RedFox wrote #289834:
it does the job too … after some tweaking:
If it works, great, though I’m a bit confused. You said “I get a <hr> between article 1 and 2 … and I only want a <hr> after 1, 2, etc. articles. And no <hr> if there are none articles.”
Isn’t that:
- Article 1
- Article 2
<hr>
and nothing output at all if there are no articles? In which case, why do you have break="hr" in your article_custom tag?
If this is what you want:
- Article 1
<hr>- Article 2
<hr>
Then you don’t need the break attribute: set it to break="", hard-code the <hr> at the end of the form and you’re done.
For the first scenario (although untested) I would expect the following to work:
<txp:article_custom
section="articles"
category="berichten"
form="single_nolink_important"
sort=""
break=""
limit="2" />
With form:
<txp:if_last_article>
<h3>Ingekomen berichten</h3>
</txp:if_last_article>
<div class="article important">
<h1 class="entry-title"><txp:title /></h1>
<txp:body />
</div>
<txp:if_last_article>
<hr>
</txp:if_last_article>
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline