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

Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.
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!

       
Danny T.'s avatar
Danny T.
426 posts
16 years ago
Danny T.'s avatar Danny T.

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.

       
Macrike's avatar
Macrike
137 posts
16 years ago
Macrike's avatar Macrike

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.

       
rockthenroll's avatar
rockthenroll
485 posts
16 years ago
rockthenroll's avatar rockthenroll

Saving this for later. Genius!

       
julie p's avatar
julie p
282 posts
16 years ago
julie p's avatar julie p

For some reason, I can only get this to work when I limit my weblog tag to 1. Ideas?

       
Robert Eerhart's avatar
Robert Eerhart
57 posts
16 years ago
Robert Eerhart's avatar Robert Eerhart

Nice work LG! This puts some magic in EE. Thanks…

       
Casey Reid's avatar
Casey Reid
82 posts
16 years ago
Casey Reid's avatar Casey Reid

Nice to see this hidden gem of a plugin getting re-noticed. I’ve used it on a number of projects, and it really is awesome. Great work as usual Leevi.

       
bmovie's avatar
bmovie
619 posts
16 years ago
bmovie's avatar bmovie

how do that with LG Replace?

  1. create 2 custom fields: Body and Notes
  2. on Publish Form fill Body with text
  3. on Publish Form fill Notes with text

goal: insert Notes inside Body on the final front end render

example: Publish Forms Body Form —————————————— I have a {notes}

Notes Form —————————————— car

DESIRE RESULT ON FRONT END: I have a car

how do that??

       
Macrike's avatar
Macrike
137 posts
16 years ago
Macrike's avatar Macrike
how do that with LG Replace? 1. create 2 custom fields: Body and Notes 2. on Publish Form fill Body with text 3. on Publish Form fill Notes with text goal: insert Notes inside Body on the final front end render example: Publish Forms Body Form —————————————— I have a {notes} Notes Form —————————————— car DESIRE RESULT ON FRONT END: I have a car how do that??

This is just an example.

{exp:weblog:entries weblog="example"}
    <h2>{title}</h2>
    {exp:lg_replace:haystack needles="notes"}
        {exp:lg_replace:replacement needle="notes"}
            {notes_custom_field}
        {/exp:lg_replace:replacement}
        {body_custom_field}
    {/exp:lg_replace:haystack}
{/exp:weblog:entries}

This code will grab the contents of the Notes custom field and place it in the body, where you put {notes}.

       
bmovie's avatar
bmovie
619 posts
16 years ago
bmovie's avatar bmovie
how do that with LG Replace? 1. create 2 custom fields: Body and Notes 2. on Publish Form fill Body with text 3. on Publish Form fill Notes with text goal: insert Notes inside Body on the final front end render example: Publish Forms Body Form —————————————— I have a {notes} Notes Form —————————————— car DESIRE RESULT ON FRONT END: I have a car how do that??
This is just an example.
{exp:weblog:entries weblog="example"}
    <h2>{title}</h2>
    {exp:lg_replace:haystack needles="notes"}
        {exp:lg_replace:replacement needle="notes"}
            {notes_custom_field}
        {/exp:lg_replace:replacement}
        {body_custom_field}
    {/exp:lg_replace:haystack}
{/exp:weblog:entries}
This code will grab the contents of the Notes custom field and place it in the body, where you put {notes}.

THANKS!!!!! IT WORKS AMAZING! THANKS Macrike!!!!

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

As I think I’ve said before, this is one of the best, yet little talked about add-ons out there. Love it.

       
bmovie's avatar
bmovie
619 posts
16 years ago
bmovie's avatar bmovie

yeah that resolve a lot things for me 😊

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
16 years ago
bhggraphicdesign's avatar bhggraphicdesign

Here’s how I got this extension to work with the TEH Textile extension and the Textile plugin.

Basically there are two things you have to do to make this work. First, since Textile already uses curly braces to write inline style, wrap your needle in parentheses and curly braces in your post. {(needle)} If you’re also using the TEH extension for your entries, you also need to tell the extension to ignore things by wrapping it with “=”, like this: ={(needle)}=.

Then you must change the html entities created by Textile back to curly braces. In the Textile plugin code just before the return of function Textile (about line 177) add this:

// reset lg_replace tags when using extension and plugin
$text = str_replace(array('{(', ')}'), array('{', '}'), $text);
$text = str_replace(array('={', '}='), array('{', '}'), $text);
$text = str_replace(array('{', '}'), array('{', '}'), $text);

This also takes out the paragraph tags added by Textile to allow things like floated images, etc. If your content needs to be in a paragraph, just wrap the “replace” content with paragraph tags.

Then you can wrap the exp:lg_replace stuff around the “textiled” content. Quick and dirty but everything works fine. For me anyway. As always, YMMV.

       
Danny T.'s avatar
Danny T.
426 posts
16 years ago
Danny T.'s avatar Danny T.

I thought of adding this into the FieldFrame thread, but determined it would be best suited for here. Is there any chance we can get LG Replace to play nicely with FieldFrame by any chance? FieldFrame can produce new rows of content on demand, so it would be simply swell it LG Replace can somehow interact with it.

Where I see this going is especially useful for tutorials, in which a multitude of screenshots/videos would be ideal to present a rich, visual experience for users. Making tons of weblog fields would work, but that certainly doesn’t beat the ease and convenience of FieldFrame Matrix.

Cheers, Danny

       
Macrike's avatar
Macrike
137 posts
16 years ago
Macrike's avatar Macrike

Hi there,

I was wondering if it’s possible to add support for parameters on the needles. I want to display some images in a post, and my current solution is something like this:

{exp:weblog:entries weblog="feature" entry_id="{segment_3}"}
    {exp:lg_replace:haystack needles="img1|img2"}
        {exp:lg_replace:replacement needle="img1"}
            {exp:gallery_extended:entries gallery_name="reportajes" entry_id="{img1_id}" limit="1" related_id="{entry_id}" type="weblog" dynamic="off" disable="member_fields|date_fields"}
                <div class="image">
                    {exp:imgsizer:size src="{image_url}" width="598" quality="80"}
                    {sized}
                    {/exp:imgsizer:size}
                    {caption}
                </div>
            {/exp:gallery_extended:entries}
        {/exp:lg_replace:replacement}
        {exp:lg_replace:replacement needle="img2"}
            {exp:gallery_extended:entries gallery_name="reportajes" entry_id="{img2_id}" limit="1" related_id="{entry_id}" type="weblog" dynamic="off" disable="member_fields|date_fields"}
                <div class="image">
                    {exp:imgsizer:size src="{image_url}" width="598" quality="80"}
                    {sized}
                    {/exp:imgsizer:size}
                    {caption}
                </div>
            {/exp:gallery_extended:entries}
        {/exp:lg_replace:replacement}
    {body}
    {/exp:lg_replace:haystack} 
{/exp:weblog:entries}

I’ve got four custom fields ({img_id}) where I write the ID of the gallery entry, and everything displays correctly. But I think it would be much better if I could do something like this:

{exp:weblog:entries weblog="feature" entry_id="{segment_3}"}
    {exp:lg_replace:haystack needles="img1|img2"}
        {exp:lg_replace:replacement needle="img1"}
            {exp:gallery_extended:entries gallery_name="reportajes" entry_id="{img_id}" limit="1" related_id="{entry_id}" type="weblog" dynamic="off" disable="member_fields|date_fields"}
                <div class="image">
                    {exp:imgsizer:size src="{image_url}" width="598" quality="80"}
                    {sized}
                    {/exp:imgsizer:size}
                    {caption}
                </div>
            {/exp:gallery_extended:entries}
        {/exp:lg_replace:replacement}
        {exp:lg_replace:replacement needle="img2"}
            {exp:gallery_extended:entries gallery_name="reportajes" entry_id="{img_id}" limit="1" related_id="{entry_id}" type="weblog" dynamic="off" disable="member_fields|date_fields"}
                <div class="image">
                    {exp:imgsizer:size src="{image_url}" width="598" quality="80"}
                    {sized}
                    {/exp:imgsizer:size}
                    {caption}
                </div>
            {/exp:gallery_extended:entries}
        {/exp:lg_replace:replacement}
    {body}
    {/exp:lg_replace:haystack} 
{/exp:weblog:entries}

And in the Publish text area, have something like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis enim sit amet lacus. Maecenas venenatis fringilla nunc. Fusce enim ante, imperdiet eget, feugiat et, dictum eleifend, sapien. {img1 img_id="246"} Suspendisse urna. Ut lobortis nisl non augue. Fusce ipsum mi, fermentum nec, convallis sit amet, elementum eget, neque. Vivamus congue. Nullam dictum, mauris sit amet commodo tempor, leo sem porttitor nibh, in interdum justo nisl ac elit. {img2 img_id="468"} Donec vitae erat consequat libero scelerisque dictum. Aenean mauris odio, pellentesque eu, interdum nec, vulputate non, dui.

Like this I could reduce the number of custom fields on the Publish page. In this example I put two images, but a normal feature article contains around 10 images/videos and the list of custom fields is rather long.

What I’m looking for is something like the embed functionality. For example:

{embed=global/header" name="Lorem Ipsum" whatever="1234"}

I hope all of that made sense. :lol:

       
1 2 3 4 Last

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.