2

I'm using Low Replace to allow users to add footnotes to the content of their entries. Anything wrapped in square brackets (like this: [[This would become a footnote.]]) will then be replaced with the appropriate markup on the front-end. Here is the code thus far:

{exp:low_replace find="SPACE\[\[(.*?)\]\]" replace="<span class=QUOTEfootnote-numberQUOTE>&sup1;</span><span class=QUOTEfootnoteQUOTE><span class=QUOTEfootnote-numberQUOTE>&sup1;</span> $1</span>" regex="yes"}
    {blog_post_content}
{/exp:low_replace}

There will often be multiple footnotes for one entry, so I need to be able to increment that &sup1; with each footnote that's found. So, for example, if there were three footnotes they would be marked-up like this:

<span class="footnote"><span class="footnote-number">&sup1;</span> Footnote content…</span>
<span class="footnote"><span class="footnote-number">&sup2;</span> Footnote content…</span>
<span class="footnote"><span class="footnote-number">&sup3;</span> Footnote content…</span>

How can I increment that number with each footnote?

1

If you could include the footnote number in the note itself, I think that'd be available via back reference in the Low Replace tag.

So, if your footnotes were like this:

[[This is a footnote.#1]]
[[This is another footnote.#2]]

Then, I think you could do this in your Low Replace tag:

{exp:low_replace find="SPACE\[\[(.*?)(\#\d+)\]\]" replace="<span class=QUOTEfootnote-numberQUOTE>&sup$2;</span><span class=QUOTEfootnoteQUOTE><span class=QUOTEfootnote-numberQUOTE>&sup$2;</span> $1</span>" regex="yes"}
    {blog_post_content}
{/exp:low_replace}

But, if changing your footnote authoring style isn't possible / practical, I think you'd have to "post process" your footnote HTML to count notes, and insert the right count per note.

  • Know how I might leave the # sign in the original but remove it when placing it? I ask because it's currently printing out as &sup#2;which is incorrect. – Brandon Durham Sep 5 '13 at 19:25
  • 1
    Figured it out: SPACE\[\[(.*?)\#(\d+)\]\] – Brandon Durham Sep 5 '13 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.