We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

LG Replace - A different kind of find and replace *NEW*

Development and Programming

adhesion's avatar
adhesion
15 posts
15 years ago
adhesion's avatar adhesion
However, by viewing page source I could see that Textile was indeed converting curly braces to entities (as you said). So, rather than your 3 replacement lines for the plugin code (around line 177), I used only one, built on your model, which looks for the HTML curly brace entities 123 and 125 (each preceded by “&#” and followed by “;”) and turns them back into the actual braces, as you do. (I’d post the actual code line, but I can’t figure out how to get this forum to let me post entities that display literally. You get the idea.)

Here’s an example of the code Spacewalk is talking about in the previous post - I used this simple solution and it worked for me too. (note, remove the space between & #123 and & #125 in the example below. The space is only there because otherwise the forum marks them up as { }’s.)

// reset lg_replace tags when using extension and plugin
$text = str_replace(array('& #123;', '& #125;'), array('{', '}'), $text);
       
spacewalk's avatar
spacewalk
106 posts
15 years ago
spacewalk's avatar spacewalk
(note, remove the space between & #123 and & #125 in the example below. The space is only there because otherwise the forum marks them up as { }’s.)
// reset lg_replace tags when using extension and plugin
$text = str_replace(array('& #123;', '& #125;'), array('{', '}'), $text);

More clever than I. 😊 Thanks for doing that.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.
Edit: If you want to be able to wrap a div or whatever around your needle when it’s inserted, you may want to keep the third line of the original plugin code mod, the one that strips Textile’s paragraph tags from around the needle.

I may need to modify this plugin to strip paragraph tags from around the needle when using XHTML. Would love to find a way to get XHTML to ignore needles when they’re the only thing on a line - sometimes I’m replacing needles with a div and a bunch of markup that I don’t want wrapped inside a ‘p’ tag.

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man
Here’s an example of the code Spacewalk is talking about in the previous post - I used this simple solution and it worked for me too. (note, remove the space between & #123 and & #125 in the example below. The space is only there because otherwise the forum marks them up as { }’s.)
// reset lg_replace tags when using extension and plugin
$text = str_replace(array('& #123;', '& #125;'), array('{', '}'), $text);

Awesome, this solved my problems with the textile formatting too. Many thanks!

       
benek's avatar
benek
189 posts
15 years ago
benek's avatar benek

Wow this is brilliant. It should be noted (if it hasn’t already) that you cannot put the exp:lg_replace:haystack tag inside your exp:weblog:entries loop. You need to surround the entire loop with it.

I’d LOVE the option of stripping paragraph tags around the needle when the field is formatted XHTML (which, for me, it’s almost always going to be when using this plugin). Right now I’m using it to inject an list of other entries into the page and the spacing issues caused by the extra paragraph tag is a problem.

       
John Ryan's avatar
John Ryan
51 posts
15 years ago
John Ryan's avatar John Ryan

I was having trouble with using both lg_replace and textile, and tried following steps outlined by bhggraphicdesign but with no look.

I’ve just made the most obvious and simple change and it all works fine. Make sure that textile formatting takes place after lg_replace has done it’s replacing. E.g.

{exp:textile}

        {exp:lg_replace:haystack needles="myfirst|mysecond"}

            {exp:lg_replace:replacement needle="myfirst"}MYFIRST{/exp:lg_replace:replacement}

            {exp:lg_replace:replacement needle="mysecond"}MYSECOND{/exp:lg_replace:replacement}

                {contents}

        {/exp:lg_replace:haystack}

{/exp:textile}

Obvious I know, but just in case anyone makes the same mistake.

       
smartpill's avatar
smartpill
456 posts
15 years ago
smartpill's avatar smartpill
I was having trouble with using both lg_replace and textile, and tried following steps outlined by bhggraphicdesign but with no look. I’ve just made the most obvious and simple change and it all works fine. Make sure that textile formatting takes place after lg_replace has done it’s replacing. E.g.
{exp:textile}

        {exp:lg_replace:haystack needles="myfirst|mysecond"}

            {exp:lg_replace:replacement needle="myfirst"}MYFIRST{/exp:lg_replace:replacement}

            {exp:lg_replace:replacement needle="mysecond"}MYSECOND{/exp:lg_replace:replacement}

                {contents}

        {/exp:lg_replace:haystack}

{/exp:textile}
Obvious I know, but just in case anyone makes the same mistake.

I’ve used bhggraphicdesign’s fix on a few sites. Did you remove those extra spaces as noted:

(note, remove the space between & #123 and & #125 in the example below. The space is only there because otherwise the forum marks them up as { }‘s.)

Won’t work if they’re still there.

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
15 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)
Wow seems this little bugger is still useful for quite a few people. I actually need to use it in my current project so I might give the code a once over to see if I can *easily* add any improvements.

LG Replace is still the only/easiest? way to include images within the text flow of an entry. So given the comment above (and 754 downloads at this time), I’m wondering why this is not available on the Levi Graham addon page or had any updates/improvements.

       
Danny T.'s avatar
Danny T.
426 posts
15 years ago
Danny T.'s avatar Danny T.
I may need to modify this plugin to strip paragraph tags from around the needle when using XHTML. Would love to find a way to get XHTML to ignore needles when they’re the only thing on a line - sometimes I’m replacing needles with a div and a bunch of markup that I don’t want wrapped inside a ‘p’ tag.

Masuga, did you ever get around to a resolution for those dreaded ‘p’ tags?

       
stinhambo's avatar
stinhambo
1,268 posts
15 years ago
stinhambo's avatar stinhambo

I just picked up on this plugin and wanted to say well done Leevi!

Now get it on your site!

       
Brian M.'s avatar
Brian M.
529 posts
15 years ago
Brian M.'s avatar Brian M.

Just wanted to put in another “thank you” for a very useful plug-in. I was trying to get reeposition to work in a conditional and having no luck. Fired this up and no problems - great plug-in - and it looks like I’m only scratching the surface regarding how to use it in a site!

Edit: turns out I’m having some weirdnesses using it in conditionals that I don’t have time now to track down. So don’t quote me on that part 😉

       
Sean C. Smith's avatar
Sean C. Smith
3,818 posts
15 years ago
Sean C. Smith's avatar Sean C. Smith
I’ve been using the LG Replace, FF Matrix combo for image uploads into content areas on the last few sites I’ve done. It really is a powerful way to give clients more control over image placement.

This sounds exactly like what I want to do with a current site. Does this work when inserting the FF Matrix combo into a wygwam field?

       
Sean C. Smith's avatar
Sean C. Smith
3,818 posts
15 years ago
Sean C. Smith's avatar Sean C. Smith

Yes this is working great. However wygwam is inserting p tags around the needle. Anyone know a way to remove those p tags?

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
15 years ago
Leevi Graham's avatar Leevi Graham

Quick note to say I have rewritten this plugin for EE2. In the short term you can grab it from Github until I move it to my new site.

Link: http://github.com/newism/nsm.replace.ee_addon

       
circa1977's avatar
circa1977
118 posts
15 years ago
circa1977's avatar circa1977

Miraculous. Not only does this:

<?php
    /* PHP Parse on Input */
    global $DB;
    $sql = "SELECT title, field_id_26
            FROM exp_weblog_titles t JOIN exp_weblog_data d ON t.entry_id = d.entry_id
            WHERE t.weblog_id = 8 AND t.status='open'";
    $links = $DB->query($sql);
    $linkList = '';
    foreach($links->result as $link) {
        $linkList .= $link['title'] . '|';
    }
?>
{exp:lg_replace:haystack needles="<?php echo $linkList; ?>|vanity-url"}
    {exp:weblog:entries weblog="site-specific-content" dynamic="off" search:site-key="={embed:site-key}" search:name="{embed:name}"}
        {detail}
    {/exp:weblog:entries}
    <?php
    foreach($links->result as $link) { ?>
        {exp:lg_replace:replacement needle="<?php echo $link['title']; ?>"}
            <?php echo $link['field_id_26']; ?>
        {/exp:lg_replace:replacement}
    <?php } ?>
    {exp:lg_replace:replacement needle="vanity-url"}
        {segment_1}
    {/exp:lg_replace:replacement}
{/exp:lg_replace:haystack}

Appear to be working, but it replaces the link list values first, and then replaces {vanity-url} within them. Not sure if there’s a more elegant way than PHP set to process on input, but am thrilled this worked so well.

       
First 2 3 4 5

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.