EllisLab text mark
Advanced Search
1 of 5
1
   
LG Replace - A different kind of find and replace *NEW*
Posted: 14 April 2008 10:34 PM   [ Ignore ]
Avatar
Joined: 2006-01-24
1210 posts

LG Replace is a different kind of text replacement plugin.

How many times have you wanted to add a dynamic date inside some user content? Or add some related links half way down an entry?

Now you can with LG Replace! Its simple to use heres the quick rundown:

1. Wrap your content in the {exp:lg_replace:haystack}{/exp:lg_replace:haystack} template tag and list the needles you would like to replace in the needles=”” attribute.

2. Add the “needles” inside the {exp:lg_replace:haystack}{/exp:lg_replace:haystack} tags. The needles must be in the following format {my_needle_id} and the needle_id must be listed as one of the needles in the needles=”” attribute of {exp:lg_replace:haystack}{/exp:lg_replace:haystack}.

3. Now that the “needles” are in our “haystack” we need to tell the plugin what to replace them with. This is done using the {exp:lg_replace:replacement}{/exp:lg_replace:replacement} tag. This tag must have an needle_id=”” attribute that links it to the needle inside of {exp:lg_replace:haystack}{/exp:lg_replace:haystack}.

That’s it. Checkout the demo below as a test.

{exp:lg_replace:haystack needles="test1|test2|test3|test4"}

    {exp
:lg_replace:replacement needle="test1"}
        Replace {test1} with this content
    {
/exp:lg_replace:replacement}

    {exp
:lg_replace:replacement needle="test2"}
        Replace {test2} with this content
    {
/exp:lg_replace:replacement}

    {exp
:lg_replace:replacement needle="test3"}
        Replace {test3} with this content
    {
/exp:lg_replace:replacement}

    {exp
:lg_replace:replacement needle="test4"}
        Replace {test4} with this content
    {
/exp:lg_replace:replacement}

Here is some content which will be replaced
:

{test1}
{test2}
{test3}
{test4}

{
/exp:lg_replace:haystack} 

I also should mention that the content of {exp:lg_replace:replacement}{/exp:lg_replace:replacement} can include other EE tags which makes this plugin very flexible and powerful.

Try it out… give it a kick in the tyres and then I will move it over to my site with better documentation

File Attachments
lg-replace.1.0.0.zip  (File Size: 3KB - Downloads: 1425)
 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 14 April 2008 10:46 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts

I can tell you at least 50 times I could have used something like this. I’ll give it a try. Thanks.

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
Posted: 14 April 2008 10:50 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-24
1210 posts
mdesign - 15 April 2008 02:46 AM

I can tell you at least 50 times I could have used something like this. I’ll give it a try. Thanks.

Yeah it seemed so simple that you would expect someone has done it before… Maybe someone has :(

I needed it for a project and couldn’t find anything so I thought I would build it myself smile

Hope you like it

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 23 April 2008 10:14 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-24
1210 posts

Dam I new I had seen something like this before!

http://ellislab.com/forums/viewthread/37240/

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 14 May 2008 05:57 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts

Leevi - I believe you have the wrong plugin inside the Zip. I keep extracting “Latest EE”, and I could use this plugin stat!

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
Posted: 14 May 2008 07:18 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-24
1210 posts

Fixed!

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 29 May 2008 05:24 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-17
173 posts

Levi, could I use this to insert images within a weblog post? for example:

{exp:lg_replace:haystack needles="test1|test2|test3|test4"}

    {exp
:weblog:entries require_entry="yes"}
      
<h1>{title}</h2>
      
{body}
    {
/exp:weblog:entries}

    {exp
:lg_replace:replacement needle="img1"}
        
<img src="/images/{image1}" />
    
{/exp:lg_replace:replacement}

    {exp
:lg_replace:replacement needle="img2"}
        
<img src="/images/{image2}" />
    
{/exp:lg_replace:replacement}

{
/exp:lg_replace:haystack} 

{image1} and {image1} are fields in the weblog that have image filenames, and then within the text of each weblog entry I have {img1} and {img2} tags.

 
Posted: 29 May 2008 05:32 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-24
1210 posts

Yeah this is possible…. I have done it on http://bitsandpixels.com.au/about/ where it says: “The next event is on Saturday 21st June”. The date is replace from outside of the loop.

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 29 May 2008 05:37 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-17
173 posts

Flippin’ brilliant

 
Posted: 29 May 2008 05:13 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts

Whoa. I can’t wait to get a few minutes to experiment with this. I’ve downloaded but haven’t had a chance yet - but that ability to insert images in there like Meirion mentions…I think I just had an epiphany about how to use this on my current site build. Cool!

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
Posted: 08 June 2008 01:22 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts

With one small needle variable “{googlemap}” I was able to drop in a whole map area with links and other stuff right into the middle of a huge block of user-controlled content. Not sure how I would have done that otherwise, other than suggesting moving the map to the bottom of the page or something. Totally awesome, man. Thanks, Leevi!

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
Posted: 09 June 2008 11:06 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2006-01-24
1210 posts

—deleted by author—

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

 
Posted: 09 June 2008 11:09 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts

Nice. I just used it to make a nice little “Read More” link on a single miscellaneous entry, without needing an excerpt plugin. This thing rules!

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
Posted: 13 September 2008 01:16 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-30
95 posts

There seems to be an issue with this plugin when using it with the TEH textile extension on a custom field. Basically I wanted to insert a link to a PDF document in the middle of a block of text. I was inserting “{pdf}” (no quotes) into the block of text within the CP, then using LG Replace to replace “{pdf}” with the actual link to the PDF which is a custom field called {static_pdf}.

Here is my code:

{exp:weblog:entries weblog="site_pages" limit="1"}
    {exp
:lg_replace:haystack needles="pdf"}
        {static_body}
     
          {exp
:lg_replace:replacement needle="pdf"}
        {static_pdf}
      {
/exp:lg_replace:replacement}
                                
    {
/exp:lg_replace:haystack}
{
/exp:weblog:entries} 

When {static_body} has the formatting set to Textile the replace doesn’t work, but changing the formatting to XHTML seems to work fine. Has anyone else been able to get this to work with Textile as the formatting option? Otherwise I’ll go a different route, maybe LG TinyMCE smile

 Signature 

Casey Reid // Clearfire, Inc. // EE Pro Network // @caseyreid

 
Posted: 14 September 2008 11:02 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-23
531 posts

I’m trying to understand how you guys are using this - in particular, Masuga.. Let me get this straight.

I have a haystack, and I designate my needle terms.. These needle terms can be inside a weblog entry body like so {needle1} and I can actually replace needle1 with a weblog custom field wrapped in code? For example, an image link inside the field processed with Image Sizer?

When the weblog entry is viewed, {needle1} would be replaced with the content as mentioned above?

If it works as above, this would be SUPER handy for things like tutorials, etc. written by members. All I’d have to do is teach them the tags that correspond to a field, such as {image1} and they can apply the images where they want. I’d format the images to make sure they are blocks, and it’d work perfect.

Another great contribution - thanks Leevi!

 
Posted: 14 September 2008 11:48 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-26
1664 posts
mr_dimsum - 15 September 2008 03:02 AM

I’m trying to understand how you guys are using this - in particular, Masuga.. Let me get this straight.

I have a haystack, and I designate my needle terms.. These needle terms can be inside a weblog entry body like so {needle1} and I can actually replace needle1 with a weblog custom field wrapped in code? For example, an image link inside the field processed with Image Sizer?

When the weblog entry is viewed, {needle1} would be replaced with the content as mentioned above?

You are absolutely correct. If I’m “injecting” an image or a PDF into the middle of, say, a large textarea, I just make sure to tell the user via the field instructions to add the tags somewhere in the field.

I use it in one case to drop a google map right in the middle of a big block of text that we couldn’t really break up into two separate chunks (text_field_1 - map - text_field_2 just wasn’t ideal). Instead of the client having to paste a big nasty google map link in the middle of the field, I have a separate custom field that uses Huot’s Geo extension. The client drops a {google_map} tag in the correct place in the textarea, and then the map is rendered perfectly, right in the middle of the textarea content, on the template side.

For the record, I also use it with Lumis’ Image Sizer plugin, similar to how you mention above, including {if} conditionals and everything.

This is very, very cool plugin and I think it’s totally underrated. Have fun!

 Signature 

Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

 
1 of 5
1