Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2018-09-18 12:53:30

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,081
Website

Re: A dynamic piece of text conditional to Textile endnotes

Cola’s is one option I had in mind; the other is at the glz_custom_fields v2 plugin, to create a set of radio buttons (this has less ambiguity).


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#14 2018-10-02 14:14:57

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: A dynamic piece of text conditional to Textile endnotes

I’ve use all the good suggestions in this thread so far, but I’m seeing a problem I overlooked before.

In my article form I have this conditional:

<txp:if_custom_field name="Endnotes?">
      <txp::endnotes />
  <txp:else />
      <p class="fin">Fin</p>
</txp:if_custom_field>

And the related custom field, ‘Endnotes?’, is setup to take ‘yes’ or nothing at all.

And in the ‘endnotes’ form:

 <p class="fin">Fin</p>
 <section class="endnotes">
    <hr>
    <h1 id="enotes">Endnotes</h1>
    <txp:yield />
 </section>

So it basically all functions such that if I don’t use endnotes for a given article, it just ends with a simple ‘Fin’. But if I do use endnotes, it gets the section wrapper tags and child elements to create the endnotes as desired.

The only problem is I’m getting this output in the web render when custom field indicates ‘yes’:

 <p class="fin">Fin</p>
 <section class="endnotes">
    <hr>
    <h1 id="enotes">Endnotes</h1>
    <txp:yield />
 </section>
 <p class="fin">Fin</p>
 <section class="endnotes">
    <hr>
    <h1 id="enotes">Endnotes</h1>
 </section>

In other words, it’s the same content in the ‘endnotes’ form twice, and the second instance (which is the oddity) is empty of any endnotes, as I would expect. But why is that markup getting repeated?

Offline

#15 2018-10-02 16:06:04

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

Re: A dynamic piece of text conditional to Textile endnotes

Hmm, I’m not sure exactly why that is, but maybe try with the bare bones first …

Sorry, scratch my answer. It make’s sense after all with what etc has posted. I didn’t realise that the txp::endnotes gets put into the article body field.


TXP Builders – finely-crafted code, design and txp

Offline

#16 2018-10-02 16:48:52

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: A dynamic piece of text conditional to Textile endnotes

It works as expected for me, you just call <txp::endnotes /> twice: in the article body, then in the article form. The latter should contain only

<txp:if_custom_field not name="Endnotes?">
      <p class="fin">Fin</p>
</txp:if_custom_field>

Offline

#17 2018-10-02 23:01:06

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: A dynamic piece of text conditional to Textile endnotes

etc wrote #314332:

. . . you just call <txp::endnotes /> twice: in the article body, then in the article form.

I don’t think I was clear, sorry. Let me try again.

In my default article form, I have the following. I want the conditional, because if I don’t say ‘yes’ to the related custom field, then only <p class="fin">Fin</p> outputs. This conditional works as desired (and a test confirms) if I don’t use the custom field to indicate ‘yes’ for endnotes:

<txp:if_custom_field name="Endnotes?">
      <txp::endnotes />
  <txp:else />
      <p class="fin">Fin</p>
</txp:if_custom_field>

In the situations where I do want endnotes, I have this in my ‘endnotes’ form, which ensures the ‘Fin’ comes after the main article text but before the endnotes:

 <p class="fin">Fin</p>
 <section class="endnotes">
    <hr>
    <h1 id="enotes">Endnotes</h1>
    <txp:yield />
 </section>

And when I say ‘yes’ to the custom field for endnotes, I also use this at bottom of the article body field, where I want the surrounding endnotes markup to output:

<txp::endnotes>

[endnotes Textile list here]

</txp::endnotes>

But as mentioned before, the markup in the ‘endnotes’ form is outputting twice for some reason.

Offline

#18 2018-10-03 05:49:02

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

Re: A dynamic piece of text conditional to Textile endnotes

I think Oleg meant this arrangement:

In your article form – your code template – do this:

<txp:body />
<txp:if_custom_field not name="Endnotes?">
      <p class="fin">Fin</p>
</txp:if_custom_field>

And in the write tab when editing your article:

1. You write the following in the body field of your article:

[Your longform text in Textile containing endnote references]

<txp::endnotes>

[endnotes Textile list here]

</txp::endnotes>

as you suggested, and …

2. You also set the custom field Endnotes? to yes.

That way your endnotes shortcode form is called once and the if_custom_field not just checks if you haven’t set the custom field, and if not puts the Fin message in.


TXP Builders – finely-crafted code, design and txp

Offline

#19 2018-10-03 05:54:51

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

Re: A dynamic piece of text conditional to Textile endnotes

Following on from that, I wonder if you could dispense with the custom field and use a variable in your endnotes form to denote whether or not there are endnotes, e.g.:

Your endnotes form would include an additional has_endnotes variable:

 <p class="fin">Fin</p>
 <section class="endnotes">
    <hr>
    <h1 id="enotes">Endnotes</h1>
    <txp:yield />
 </section>
 <txp:variable name="has_endnotes" value="yes" />

And your article code template would then end like this:

<txp:body />
<txp:if_variable not name="has_endnotes">
      <p class="fin">Fin</p>
</txp:if_variable>

Perhaps worth a try. If it works, it’s one less thing to remember to set when writing an article.


TXP Builders – finely-crafted code, design and txp

Offline

#20 2018-10-03 07:13:57

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: A dynamic piece of text conditional to Textile endnotes

I think what has been confusing me is your guy’s examples for the article form code…

<txp:if_custom_field not name="Endnotes?">
      <p class="fin">Fin</p>
</txp:if_custom_field>

What I see now, from what your repeating, is that I didn’t need to include <txp::endnotes />, like this, which was probably causing the repeating markup:

<txp:if_custom_field name="Endnotes?">
      <txp::endnotes />
  <txp:else />
      <p class="fin">Fin</p>
</txp:if_custom_field>

But, as I just tested, I do still need the conditional <txp:else />, like this:

<txp:if_custom_field name="Endnotes?">
  <txp:else />
      <p class="fin">Fin</p>
</txp:if_custom_field>

Otherwise it still outputs <p class="fin">Fin</p> at the end of the endnotes complex, which is not what I want.

So it seems to be working now with that change, using the custom field method.

Offline

#21 2018-10-03 07:40:59

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: A dynamic piece of text conditional to Textile endnotes

jakob wrote #314337:

Following on from that, I wonder if you could dispense with the custom field and use a variable in your endnotes form to denote whether or not there are endnotes

Very cute!

Offline

#22 2018-10-03 07:44:43

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: A dynamic piece of text conditional to Textile endnotes

Destry wrote #314338:

But, as I just tested, I do still need the conditional <txp:else />

You mean, not is not working?

<txp:if_custom_field not name="Endnotes?">
      <p class="fin">Fin</p>
</txp:if_custom_field>

Then I’d need to investigate. But try @jacob suggestion, you won’t need to fill a custom field if it works.

Offline

#23 2018-10-03 08:28:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: A dynamic piece of text conditional to Textile endnotes

Destry wrote #314338:

I think what has been confusing me is your guy’s examples for the article form code…

<txp:if_custom_field not name="Endnotes?">...

What I see now, from what your repeating, is that I didn’t need to include <txp::endnotes />, like this, which was probably causing the repeating markup:

<txp:if_custom_field name="Endnotes?">...

But, as I just tested, I do still need the conditional <txp:else />, like this:

<txp:if_custom_field name="Endnotes?">...

Otherwise it still outputs <p class="fin">Fin</p> at the end of the endnotes complex, which is not what I want.

So it seems to be working now with that change, using the custom field method.

Indeed you are right

another option is

<txp:if_custom_field name="Endnotes?" not>
      <p class="fin">Fin</p>
</txp:if_custom_field>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#24 2018-10-03 08:34:02

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: A dynamic piece of text conditional to Textile endnotes

Arg! I didn’t even notice the not part. And of course I didn’t just copy/paste your code (except in my example here) so it wasn’t getting added in the test.

Yes, this works now:

<txp:if_custom_field not name="Endnotes?">
      <p class="fin">Fin</p>
</txp:if_custom_field>

Sorry.

I will try Jakob’s trick now too…

Yep, the variable method works!

That’s all pretty sweet. I would never have figured it out on my own. Thanks a tonne!

Last edited by Destry (2018-10-03 08:40:48)

Offline

Board footer

Powered by FluxBB