Hop Inject
Current Version: 5.2.0- EE3
- EE4
- EE5
- EE6
- EE7
-
Installation
- Unzip the folder to a temporary location on your local hard drive.
- FTP the files from their local folders to the same locations in your EE install’s /system/user/addons/ folder on the server.
- Navigate to Add-ons in your EE control panel and install the add-on. That’s it!
-
Usage
- Wrap the content to be processed in the
{exp:hop_inject}template tag.{exp:hop_inject where="<p>" always_inject="yes"} Content into which you want to inject other elements. {/exp:hop_inject}- The where parameter gets a string that determines where an injection might occur, as determined by use of the
{exp:hop_inject:injection}tag (See step 2). - The always_inject parameter determines what happens to injections that are outside the bounds of the content. For example, if you specify an injection at the tenth paragraph tag, but there are only seven paragraphs, what should happen to that injection?
If always_inject=”yes”, then the injection will simply appear after the entire block of content. If it’s no, the block will be ignored. yes is the default value.
Bonus: A negative number like -1000 puts the injected text appear before the entire block of content.
- The where parameter gets a string that determines where an injection might occur, as determined by use of the
- Wrap each element you want to inject with
{exp:hop_inject:injection}tags.
Use multiple{exp:hop_inject:injection separator="1" position="before"} Element to inject. {/exp:hop_inject:injection}{exp:hop_inject:injection}for each element to be injected.- The separator parameter is very flexible. It represents the count of the element that’ll get the injection.
You can clone content this way, too, by injecting it multiple times: separator=”3|6|9”
Using a negative number for the separator counts up from the bottom. For example, separator=”-4” injects the element at the fourth separator occurrence from the bottom.
You can also use percentage values like separator=”33%” which will inject the content at 33% location.
You can even use conditions like separator=”> 5 : 90%” to compare 2 values and inject the content to the matching condition. In this case, the content will be injected to the 5th location or 90% location, whichever is greater.
- The position parameter is either before or after. By default, the injection will be made before the separator. Or you can use type=”replace” to replace the matched where.
- The separator parameter is very flexible. It represents the count of the element that’ll get the injection.
- Wrap the content to be processed in the
-
Example: Simple
Image a body field that has an HTML comment for where you want to add the edit_date of an entry, like:
This entry was updated on <!-- edit_date -->Normally, that would have to be done in your template separate from your body content, so it couldn’t be inline within your writing. Or you’d have to use javascript or something else after the page loaded to move the data around the DOM.
With Hop Inject, just do this:
{exp:hop_inject where="<!-- edit_date -->" always_inject="yes"} {page_body} <!-- contains the edit_date tag --> {exp:hop_inject:injection separator="1" position="after"} {edit_date format="%M %j, %Y"} {/exp:hop_inject:injection} {/exp:hop_inject} -
Examples: Advanced
{exp:hop_inject where="</p>" always_inject="yes"} {exp:hop_inject:injection separator="1" position="after"} <span>Put this text after the first paragraph closing tag.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="8" position="before"} <span>Put this text before the eighth paragraph closing tag (in the 8th paragraph).</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="2|3" position="after"} <span>Put this text after the second AND third paragraph closing tags.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="8"} <span>Put this text before the eighth paragraph closing tag, too.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="-4" position="after"} <span>Put this text after the 4th paragraph closing tag counting from the end.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="300"} <span>Because of the large number, this text will appear after the entire content block.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="33%" position="before"} <span>Put this text before the calculated location at 33% of the paragraph closing tags.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="> 4 : 10%" position="before"} <span>Put this text before the 4th paragraph or 10% of the paragraph closing tags, whichever is bigger.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="> 5 : 90%" position="before"} <span>Put this text before the 5th paragraph or 80% of the paragraph tags, which ever is bigger.</span> {/exp:hop_inject:injection} {exp:hop_inject:injection separator="5" type="replace"} <span style="color: red;">Put this text in place of the 5th <p> tag.</span> {/exp:hop_inject:injection} <p>1</p> <p>2</p> <p>3</p> <p>4</p> <p>5</p> <p>6</p> <p>7</p> <p>8</p> <p>9</p> <p>10</p> {/exp:hop_inject}Check out the
example.group/templates for more examples. -
Updating
Updating is easy:
- Download a new version from this website, and extract on your hard drive.
- Upload the new files to their appropriate locations.
-
Uninstalling
- Navigate to the Add-Ons > Modules tab in your EE control panel and uninstall the module.
- Remove the add-on directory from your EE system folder on the server.