Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-06-24 21:56:46

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 267
Website GitHub Twitter

Do not repeat yourself

I have two forms that are identical, apart from one which displays the excerpt field. I’m looking for the simplest/cleanest way to use a single form instead.

Using <txp:article noexcerpt listform="thumb" wraptag="ul" break="li" etc etc /> on my page and this snippet in form thumb.txp:

<txp:if_yield name="noexcerpt">
  <txp:excerpt />
</txp:if_yield>

would be the simplest, but doesn’t work as <txp:yield /> only works with shortcodes and output_form.

I can:

  • use <txp:article class="hide--excerpt" listform="thumb" wraptag="ul" break="li" etc etc /> and use css to hide the excerpt, but its kludgy.
  • call the form with <txp::thumb noexcerpt etc /> but I’ll need to duplicate all the wraptag, class, break, sort etc attributes for my <txp:article>… block within form thumb.txp. I’ll also need to account for the article tag’s automatic list/individual_article discrimination.
  • still use 2 forms thumb.txp and thumb_noexcerpt.txp, each a shell calling on a collection of shortcodes eg. <txp::thumb_title />, <txp::thumb_image />, etc. I’m not wild about this approach either.
  • use <txp:variable name="noexcerpt" value="1" /> higher up on the page and <txp:if_variable name="noexcerpt" value="1">etc in my form. This is the simplest approach I can come up with, but I don’t lark ut.

Am I missing something that’s obvious to everyone else?

Last edited by giz (2022-06-24 22:13:08)

Offline

#2 2022-06-25 06:04:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,719
Website

Re: Do not repeat yourself

Untried, but could you use txp:article as a container tag and place your output_form within that. Something like?

<txp:article wraptag="ul" break="li" etc etc>
    <txp:output_form form="thumb" noexcerpt />
</txp:article>

Alternatively, if you do use two forms, simply place the output_form bit in thumb_noexcerpt.txp to call thumb (.txp) with the yield value set.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2022-06-25 18:16:08

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 267
Website GitHub Twitter

Re: Do not repeat yourself

Now why didn’t I think of that?

Thank you jakob!

Offline

Board footer

Powered by FluxBB