ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Backspace for custom field

June 04, 2011 5:05pm

Subscribe [2]
  • #1 / Jun 04, 2011 5:05pm

    Marien

    56 posts

    For a blog I want to add Google’s +1 buttons inline on the end of the body text. To do this I want the code below to appear just before the very last </p>-tag. Like this:

    <g:plusone size="small"></g:plusone>

    The body will be full HTML, so there can be multiple paragraphs. I looked at the Find & Replace plugins, but none of them seem to have an option to replace only the very last instance of </p>. Backspacing 4 chars could also solve the issue.

    What would be the best way to do this? With php str_replace(), all quotes remain in the {body}-text, so it gets me syntax errors (a tip to prevent that from happening would help too).

  • #2 / Jun 06, 2011 5:26am

    John Henry Donovan

    12339 posts

    Marien,

    Is adding that code to your template not an option? and then just deleting the closing tag from your publish field?

    {body_text}
    <g:plusone size="small"></g:plusone>
  • #3 / Jun 06, 2011 8:55am

    Marien

    56 posts

    No, I don’t want to edit any data itself, and the field will be using a WYSIWYG interface, so that’ll be a problem.

  • #4 / Jun 07, 2011 5:48am

    John Henry Donovan

    12339 posts

    Marien,

    I looked at the Find & Replace plugins, but none of them seem to have an option to replace only the very last instance of

    Ok if we think about this laterally. In your template just after this field add a unique character like an asterisk so

    {body_field}*

    Now with your Find replace plugin, replace

    *
    with
    <g:plusone size="small"></g:plusone>

    Do you think that might work?

  • #5 / Jun 07, 2011 8:22am

    Marien

    56 posts

    Very smart, thanks! That works just perfectly!

  • #6 / Jun 07, 2011 10:36am

    Kevin Smith

    4784 posts

    Glad John was able to get you taken care of, Marien!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases