In my last project I needed a convenient way to inject one piece of content in another.
In specific the text for the page was a single Textile-formatted textarea field. But we have the options of images with possible captions for the client to upload via Mark Huot’s File Extension. I wanted an easy way to throw a div of images in between paragraphs and while I was at it why not much more.
Thus exp:fl_inject was born. (Was worried Inject might be common as per the docs so I named the class to Fl_inject to be safe.)
With this plugin you can grab code and place it elsewhere. Sort of like reeposition, but you don’t have to do this in the same tag pair and you can sort of search/replace where you want to place the code.
Parameters for {exp:inject}: - inject_id (default: ‘_default’) Name or index of the variable you are trying to save or inject. - where (default: ”) Text to match that serves as the pivot for injection or replacement - method (default: ‘after’) Can be either ‘before’, ‘after’, or ‘replace’
Use exp:fl_inject:capture to grab the text you want to inject. E.g.
{exp:fl_inject:capture inject_id="images"}
{file}
{file_url}
{/file}
{/exp:fl_inject:capture}
Then use exp:fl_inject to inject the captured text.
{exp:fl_inject inject_id="images" where="Images after this colon:" method="after"}
<div>Images after this colon:</div>
{/exp:fl_inject}
Note “Images after this colon:” can be text inside a field.
The original application was for a page like this: http://www.nylandmarks.org/about_us/
I wanted to place the images after the first paragraph thus if you were to use the plugin without any parameters
{exp:fl_inject}
is the same as
{exp:fl_inject inject_id="_default" where="</p>" method="after"}
So if you are using the capture and inject only once on a given set of templates you probably don’t need to specify the inject_id parameter.
I’ve used it in a number of other ways for example if I have multiple weblog tags on the same page and want data from one to be used in another without having to call the DB, use PHP, or otherwise do the same work over again. If you keep the template parsing order in mind you can get creative with this.
Oh also there is an append function. Capture will overwrite, append will add to what’s there ({exp:fl_inject:append}).
Possible caveats: -My regex is weak, but so far so good.
Versioning is arbitrary. Released at 0.1.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.