Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

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

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 />


    data='<txp:body />'
    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>'

    <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>


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



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


Board footer

Powered by FluxBB