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

Craig Allen's avatar
Craig Allen
135 posts
16 years ago
Craig Allen's avatar Craig Allen

Hello,

I want to use imgsizer plugin on images inserted by TinyMCE. It inserts them as a standard image tag …

this/is/the/path.jpg

So I need to turn that into …

{exp:imgsizer:size width="300" src="this/is/the/path.jpg"}

… in order for imagsizer to do it’s magic and then regenerate the original <img> tag.

So I figured I could use the lg_replace plugin to swap the start and end of the img tag for those of the exp:imgsizer:size tag.

However, I’ve tried the following without success.

{exp:lg_replace:haystack needles="<img|.jpg">"}

    {exp:lg_replace:replacement needle="<img"}
{exp:imgsizer:size 
    {/exp:lg_replace:replacement}

    {exp:lg_replace:replacement needle=".jpg">"}
.jpg"}
    {/exp:lg_replace:replacement}

    {body_text}

{/exp:lg_replace:haystack}

I think that the use of “, / and } characters in the needle and replacement text is probably the problem. I thought that escaping them with backslashes might work, but no.

Does anyone have any thoughts on this please.

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

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.

       
Briggs's avatar
Briggs
111 posts
16 years ago
Briggs's avatar Briggs

This is really helpful, but, I don’t think it will work with moving pagination, correct?

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg
This is really helpful, but, I don’t think it will work with moving pagination, correct?

Check out REEposition for moving pagination, if you can find it around.

       
Jules van Schaijik's avatar
Jules van Schaijik
209 posts
16 years ago
Jules van Schaijik's avatar Jules van Schaijik

I was hoping I could use the lg_replace plugin to test whether or not comments are allowed outside the exp:weblog:entries tag. I thought I could store the value for {allow_comments} in the haystack, and then use it in a conditional later on. But I can’t get the conditional to work. Any ideas how to solve my problem?

Here’s the relevant code:

{exp:lg_replace:haystack needles="comments_yes_or_no"}

{exp:weblog:entries limit="1"}
{exp:lg_replace:replacement needle="comments_yes_or_no"}
{allow_comments}
{/exp:lg_replace:replacement}
{/exp:weblog:entries}

{exp:weever}
{exp:comment:entries limit="999" weever="on"}
{if comments_yes_or_no == "y"} -- Insert Reply Button Here -- {/if}
{/exp:comment:entries}
{/exp:weever}

{/exp:lg_replace:haystack}
       
iain's avatar
iain
317 posts
about 16 years ago
iain's avatar iain
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

I’m just playing around now with this and Fieldframe, I’ve setup a matrix with a file uploader and a text area (image and caption)… would be awesome if the client could just insert {image_1} through {image_x} for inserting images to the main content field.

Can’t figure out the right logic though, or if its even possible,

has anyone done this or similar with the plugin?

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

Have you guys seen this screencast at Vimeo called “ExpressionEngine HowTo: FF Matrix + LG TinyMCE + imgsizer + LG Replace”? That may get you started.

       
iain's avatar
iain
317 posts
about 16 years ago
iain's avatar iain

well, if I’m not mistaken this is working and has just blown away my mind with possibilities:

<h1>{title}</h1>

{exp:lg_replace:haystack needles="{page_images}image_{row_count}|{/page_images}"}
    {page_images}    
        {exp:lg_replace:replacement needle="image_{row_count}"}
            <div class="foo">{image_upload}{image_caption}</div>
        {/exp:lg_replace:replacement}
    {/page_images}

    {page_content}
            
{/exp:lg_replace:haystack}

My fieldframe matrix is called {page_images}, and within {page_content} the client simply inserts {image_x} where x is the row they want to reference in the fieldframe matrix…

Wow, what an awesome plugin.

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

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.

       
iain's avatar
iain
317 posts
about 16 years ago
iain's avatar iain
Have you guys seen this screencast at Vimeo called “ExpressionEngine HowTo: FF Matrix + LG TinyMCE + imgsizer + LG Replace”? That may get you started.

Just came across that after I posted the code sample lol

great minds think alike and all that 😊

       
iain's avatar
iain
317 posts
about 16 years ago
iain's avatar iain

Just a quick one to see if you guys might be interested in a Matrix CellType I’ve been working on:

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

       
gwineman's avatar
gwineman
19 posts
about 16 years ago
gwineman's avatar gwineman

Awesome… Wish I had found this last week. Nicely done

       
Fred Boyle's avatar
Fred Boyle
73 posts
about 16 years ago
Fred Boyle's avatar Fred Boyle

Having some issues with this, not quite sure why it’s not working. Anyone care to help?

Here’s my template code:

{exp:lg_replace:haystack needles="product_list"}

        {exp:lg_replace:replacement needle="product_list"}
            {if segment_2 == "citrus"}
                <ul>
                {exp:weblog:entries search:product-type="Citrus Solvent" dynamic="off" weblog="products" limit="9999" orderby="title" sort="asc"}
                    <li>{exp:strip_p}{exp:textile}{title}{/exp:textile}{/exp:strip_p}</li>
                {/exp:weblog:entries}
                </ul>
            {/if}
        {/exp:lg_replace:replacement}

    <div id="content">
        {exp:weblog:entries}
            <h2>{title}</h2>

            {content}
        {/exp:weblog:entries}
        
    {/exp:lg_replace:haystack}

In the {content} field I’ve put in the {product_list} tag to be replaced, but on output the tag is not replaced as expected. Am I doing something wrong? Is it because my {content} field is Textile format?

       
Ridge's avatar
Ridge
44 posts
15 years ago
Ridge's avatar Ridge

Hey guys, I’m having some problems.

I have 2 custom fields, {main_content} and {main_extended}. I’m using LG Replace, and FF Matrix with my {main_content} and {main_extended} custom fields set to use the JM WYMEditor fieldframe (http://ellislab.com/forums/viewthread/125927/).

Here’s the issue: If {main_extended} is set to use WYMEditor, the whole page crashes and burns quite spectacularly: http://www.easterlydev.com/about/community-involvement/. It does the same if both {main_content} and {main_extended} use WYMEditor. However, if I set the field type of {main_extended} to straight textarea, all is well.

With the help of Kurt Deutscher (thanks Kurt!) we were able to determine that SOMETHING doesn’t like a closing curly brace in the {main_extended} custom field. Whether that something is LG Replace or WYMEditor, I’m not sure. I’ve posted this in both the LG Replace thread and the JM WYMEditor thread in hopes that someone cleverer than me can figure this out. 😊

       
spacewalk's avatar
spacewalk
106 posts
15 years ago
spacewalk's avatar spacewalk
Here’s how I got this extension to work with the TEH Textile extension and the Textile plugin.

Thanks for this excellent post, which pointed the way for me. However, my experience was slightly different (and simpler). I’m using the Textile plugin (v.1.1.1 (2.0.0 r2779)) and Textile Editor Helper (TEH) extension 1.2. Maybe the later version of TEH explains the difference in my experience, but I do not need to wrap parentheses or “=” around my needle to get it to work.

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.)

And with that, the LG Replace plugin seems to work just fine with Textile, using a plain old LG Replace needle like {images1} – no “()” or “==” wrapped around it.

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.

       
1 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.