Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
Offline
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
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
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
Re: A dynamic piece of text conditional to Textile endnotes
Nice :-)
TXP Builders – finely-crafted code, design and txp
Offline
Re: A dynamic piece of text conditional to Textile endnotes
I forgot I was using the custom field for two purposes. Heh. So I might have to go back to the custom field approach. I’ll run it by you and please tell me what is the cleanest approach.
In addition to all the previous for adding ‘Fin’ in relation to endnotes lists, I also had a parenthetical note up at top of article in relation to word counts which informed readers that part of the large word counts were due to the meaty endnotes. It’s all in what I call the ‘publine’, which appears between the subtitle and excerpt, and concerns a couple of conditionals, actually, but for different situations:
<p class="publine">
<txp:hide>
If About article (id=1) then word count only. Else, author, date and word count.
</txp:hide>
<txp:if_article_id id="1">
<txp:evaluate query='<txp:smd_article_stats item="body,excerpt" break="+" />' escape="number" /> words
<txp:else />
<txp:author /> <span>○</span> <a href="<txp:site_url /><txp:article_url_title />" title="<txp:title escape="textile,tags" /> permlink"><txp:posted /></a> <span>○</span> <txp:evaluate query='<txp:smd_article_stats item="body,excerpt" break="+" />' escape="number" /> words
<txp:if_custom_field name="Endnotes?">
<span class="clause">
(including <a href="<txp:article_url_title />#enotes">endnotes</a>)
</span>
</txp:if_custom_field>
</txp:if_article_id>
</p>
The part in focus here is:
<txp:if_custom_field name="Endnotes?">
<span class="clause">
(including <a href="<txp:article_url_title />#enotes">endnotes</a>)
</span>
</txp:if_custom_field>
So it seems to me I either bring back the ‘Endnotes?’ custom field to work in both places, but with and without not, respectively. Or I would have to create a second variable for this new situation? In which case I would need help with that tag structure.
Considering both cases together, what is the most concise solution?
Offline
Re: A dynamic piece of text conditional to Textile endnotes
The if_variable depends on the endnotes shortcode form having been processed before the if_variable conditional statement, so a couple of loose ideas:
The simplest way: put the wordcount at the bottom! or in a sidebar that appears in the code sequentially after txp:body. Then you can use the same pattern as above.
If you want publine at the top, another way might be to encapsulate the entire txp:body block including Fin in a variable first, then do your publine and output the variable containing body+fin after the publine. Something like this:
<!-- pre-process txp:body and store for later use -->
<txp:variable name="article_body_content">
<txp:body />
<txp:if_variable not name="has_endnotes">
<p class="fin">Fin</p>
</txp:if_variable>
</txp:variable>
<!-- your article title and publine code goes here -->
<!-- now output your article content -->
<txp:variable name="article_body_content" />
and in your highlighted part of the publine segment you use:
<txp:if_variable name="has_endnotes">
<span class="clause">
(including <a href="<txp:article_url_title />#enotes">endnotes</a>)
</span>
</txp:if_variable>
TXP Builders – finely-crafted code, design and txp
Offline
Re: A dynamic piece of text conditional to Textile endnotes
In 4.7 you can alter the parsing order within <txp:evaluate />:
<txp:evaluate test="body">
<p class="publine">
...
<txp:if_variable name="has_endnotes">
<span class="clause">
(including <a href="<txp:article_url_title />#enotes">endnotes</a>)
</span>
</txp:if_variable>
...
</p>
<txp:body />
<txp:if_variable not name="has_endnotes">
<p class="fin">Fin</p>
</txp:if_variable>
</txp:evaluate>
This will process <txp:body /> first, then all the rest.
Offline
Re: A dynamic piece of text conditional to Textile endnotes
etc wrote #314376:
In 4.7 you can alter the parsing order with
<txp:evaluate />
Brilliant! Another one of those great txp 4.7 aha moments.
TXP Builders – finely-crafted code, design and txp
Offline
Re: A dynamic piece of text conditional to Textile endnotes
Awesome! I wanted to keep the count at top where it’s immediately visible, so 4.7 and evaluate for the win! Thanks again, maestros.
Offline