Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2017-06-05 21:15:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 997
Website

Re: From PHP to txp:plugin -- need help troubleshooting!

I found a solution!

In cases where the target pattern //span[@class=‘fnt’] doesn’t exist in the content, I don’t need to run the search-and-replace with etc_query.

So, after learning a little about XPath, I set a variable that gets content only when the target pattern is present in the content. Then I use Textpattern’s if_variable to check it: If the target pattern isn’t there, I return the content without parsing it with etc_query. If the target pattern is present, I run search and replace, as follows:

<txp:variable name="has_notes"><txp:etc_query data='<txp:body />' query="//span[@class='fnt']"/></txp:variable>

<txp:if_variable name="has_notes" value="">

  <txp:body />

  <txp:else/>






  <txp:etc_query
    data='<txp:body />'
    globals="variable"
    query="//span[@class='fnt']"
    replace='&=<sup><a href="#endnote_{$+({?endnote_no}|{#row})}x<txp:article_id/>" id="marker_{$+({?endnote_no}|{#row})}x<txp:article_id/>">{$+({?endnote_no}|{#row})}</a></sup>'
    specials="replace,content"
    >

    <txp:variable name="endnotes">

      <txp:variable name="endnotes"/>

      <li id='endnote_{$+({?endnote_no}|{#row})}x<txp:article_id/>'>{text()} <a href='#marker_{$+({?endnote_no}|{#row})}x<txp:article_id/>'>^</a></li>

    </txp:variable>

    {$=({#row}|{#rows}).?({//body/node()}<txp:variable name="endnote_no" value="{$+({?endnote_no}|{#row})}" />)}

  </txp:etc_query>

</txp:if_variable>

Last edited by johnstephens (2017-06-05 21:16:50)

Offline

Board footer

Powered by FluxBB