Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2018-10-03 09:09:33

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

Re: A dynamic piece of text conditional to Textile endnotes

Nice :-)


TXP Builders – finely-crafted code, design and txp

Offline

#26 2018-10-04 07:02:07

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

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

#27 2018-10-04 08:12:25

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

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

#28 2018-10-04 08:22:07

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

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

#29 2018-10-04 09:24:47

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

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

#30 2018-10-04 10:05:56

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

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

Board footer

Powered by FluxBB