This step by step guide shows you how to develop your own add-on, allowing you to insert a dynamic HTML block in your emails with data pulled from an other extension.
You may want to send to your users the latest products you have in store this month, the upcoming events they can book, or your latest articles built with an other extension.
To do this, you can either copy your content title, image, description, etc... or you can use one of our add-ons.
If we don't have any add-on yet for the extension you're using, you can create it using this guide, which will add a new block type in our email editor:
As an example, here is a simple Joomla article inserted in an email:
For this step by step guide, we will create an integration with Phoca download that lets you:
search and insert a file
insert files by category
Base file
Before continuing, make sure you created a custom add-on by following this guide:
on line 4, we make sure the Phoca Download extension is installed. AcyMailing won't show the block type if this is not the case. If you don't need to check for an extension to be installed, remove this line
on line 6, the name you set will be shown on your block type
on line 7, the URL must point to your icon image
Define the insertion options
For your integration to be visible in the editor, you will need to add the following method to your plugin.php file:
If you return null in this method, your integration won't be shown. This gives you the possibility to add conditions here.
At this point your new block type should be visible in the editor:
To define the insertion options that will be shown in the right panel of the editor, you will need to add this use statement at the top of the plugin.php file:
You will need to modify multiple parts of this method:
line 4, we need to get the Phoca Download categories to be able to filter files. AcyMailing always needs the id, parent_id and title columns. If these columns have a different name for your extension, you must use the SQL "AS" to rename the column in the pulled data
if your extension's main parent category ID is 0, you need to add $this->rootCategoryId = 0; into the add-on's construct method. This will help AcyMailing display the categories correctly on the listing
line 10 we define the most common options shown in the right panel, you may want to modify the lines 16 to 18 if you want to have more data to display in your email
lines 61 to 64, we define the possible columns used to order the files when multiple ones are inserted by category
You will also need to add this method to prepare the listing showing the content you can insert:
line 3, we get the columns needed to show the content that can be inserted. You should always at least get the id and the title
line 4, we define in which table we get the content that can be inserted.
we can filter the content shown in the insertion options by adding conditions in the filter line 7. In this case, we chose to only show the files that are published
line 7, we get the columns on which we want the search field to be applied when searching for a content to insert
line 8, we define the column used to order the results. We chose to show the files by id (recent files first)
line 9, we define the table containing the information we need. We often apply the alias "item" on the main table to make the query shorter
lines 10 and 36, we define the column name containing the id (often "id", but some extensions can have "ID", "content_id", etc...)
line 15, we add a condition if a category is selected in the category filter. In this case, the category id of a file is stored in the column "catid"
lines 21, 25 and 30 must use the column names that are selected on line 3. These will be shown on the files listing. You can add as many columns as you want, but you should always make sure that the total size is always 12. In this example, the title has a size of 7 (line 23), the publishing date has a size of 4 (line 27) and the id has a size of 1 (line 32)
At this point you should see your insertion options on the right panel after dragging your new block type into an email:
Dynamically insert a content one by one in an email
Now that we have our insertion options, we can at the code inserting our content into the email. For this, add this method to your plugin.php file:
line 3, you need to make an SQL query that gets all the data you need to display in your email. The id of the selected content can be found in the variable $tag->id.
on line 10 you need to build the URL that shows the content on the front-end of your website. It will be added to the title and image of the inserted content
lines 18 to 34, we look at the options checked in $tag->display and prepare the data we want to display. All the options selected in the editor's insertion options are stored in $tag, and the data of the content to insert is is $element
lines 36 to 43, we create an object used by our code to automatically generate the HTML to insert in the email. Note that you could simply return the HTML you want, but using our code makes life easier to handle most of our options automatically (shorten the description, resize/remove images, add a link to the title/image, etc...)
You should now be able to insert a single element with your new block type:
Dynamically insert content by category in an email
Now that our custom add-on lets us insert file listings one by one, we can make it insert them in bulk.
Start by modifying the method replaceContent that we previously added, and call the function replaceMultiple like this, just before calling replaceOne:
This basically builds an SQL query that gets the file listing IDs that should be inserted in the email, based on what you selected in the insertion options:
line 16 we select the id of the Phoca Download files
on line 22, we make sure only the files in the selected categories are inserted. If the category relationship is stored in an other table you may need to adapt the query and join on this other table for example
line 25 to 27 we make sure only published files are inserted
the lines 29 to 39 are only useful if you want to use your integration with automatic campaigns. This makes sure that the auto-campaign is only sent if the minimum number of files inserted is met, and that the same file isn't inserted in multiple campaigns
At this point your integration is ready and you should be able to insert the content either one by one or by category in your emails!