1 of 4
1
LG Replace - A different kind of find and replace *NEW*
Posted: 14 April 2008 09:34 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

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: 1376)
 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

Profile
 
 
Posted: 14 April 2008 09:46 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006

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

 Signature 

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

Profile
 
 
Posted: 14 April 2008 09:50 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006
mdesign - 15 April 2008 01: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

Profile
 
 
Posted: 23 April 2008 09:14 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

Dam I new I had seen something like this before!

http://expressionengine.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

Profile
 
 
Posted: 14 May 2008 04:57 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006

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

 Signature 

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

Profile
 
 
Posted: 14 May 2008 06:18 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

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

Profile
 
 
Posted: 29 May 2008 04:24 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  188
Joined  10-17-2007

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.

Profile
 
 
Posted: 29 May 2008 04:32 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

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

Profile
 
 
Posted: 29 May 2008 04:37 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  188
Joined  10-17-2007

Flippin’ brilliant

Profile
 
 
Posted: 29 May 2008 04:13 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006

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 

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

Profile
 
 
Posted: 08 June 2008 12:22 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006

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 

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

Profile
 
 
Posted: 09 June 2008 10:06 PM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

—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

Profile
 
 
Posted: 09 June 2008 10:09 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006

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 

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

Profile
 
 
Posted: 13 September 2008 12:16 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  04-30-2007

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

Profile
 
 
Posted: 14 September 2008 10:02 PM   [ Ignore ]   [ # 14 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  555
Joined  04-23-2008

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!

Profile
 
 
Posted: 14 September 2008 10:48 PM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1757
Joined  03-26-2006
mr_dimsum - 15 September 2008 02: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 

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

Profile
 
 
Posted: 14 September 2008 11:54 PM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  555
Joined  04-23-2008

Thanks for the clarification mate! I’ll be sure to incorporate this into the mix somehow! Yes, definitely under-rated! I’m quite surprised it hasn’t received more notice actually.. This is actually something I’ve been DYING to have to improve workflow and to improve accessibility for more social-centric sites I’d have on the plate.

Profile
 
 
Posted: 19 October 2008 12:40 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  167
Joined  04-25-2008

Interesting. I was looking for a way to inject quotes and images into large blocks of text, and this seems perfet.

Gonna try it out.

Profile
 
 
Posted: 25 November 2008 11:11 AM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  522
Joined  07-16-2005

Saving this for later. Genius!

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

Profile
 
 
   
1 of 4
1