Search
Other Content Templater questions
Forum

Template AutoLoad not working for Articles created by API call

Andre Ruediger's Avatar Andre Ruediger
Hi,

I have created a template and enabled AutoLoad by default.
Now, when I create a new article through the backend, the template is automatically loaded.

However, if I create an article through the API, the template is not loaded.
The template is only loaded when I open the newly through the API created article in the backend editor.

How can I achieve that the template is also loaded directly for articles created via the API?

BR
Peter van Westen's Avatar Peter van Westen ADMIN
Content Templater cannot be triggered via the API.
All Content Templater does is (pre)fill fields in the article edit form. It doesn't save data or inject data in php objects.
Please post a rating at the Joomla! Extensions Directory
Andre Ruediger's Avatar Andre Ruediger
ok, then please write it exactly like that in the description of the plugin on your website.
There it says that every newly created article can be filled.
This is misleading at this point. It is also not apparent in the documentation or the free version.

I would then try to create a plugin that automatically loads a defined template from Content Templater into each newly created article.
I have never done this before but I would follow this tutorial:
kevinsguides.com/guides/webdev/joomla4/r...ent-plugins-with-exs

for the php file I would start with the following code:
<?php
defined('_JEXEC') or die;

class plgContentMyApiTemplateLoader extends JPlugin
{
    public function onContentAfterSave($context, $article, $isNew)
    {
        if ($context === 'com_content.article' && $isNew)
        {
            $templateId = 1; // Die ID des gewünschten Content Templater-Templates
            $template = $this->loadContentTemplaterTemplate($templateId);

            if ($template)
            {
                $article->text = $template;
                $article->store();
            }
        }
    }

    private function loadContentTemplaterTemplate($templateId)
    {
        // load Content Templater Classes
        require_once JPATH_SITE . '/components/com_contenttemplater/helpers/contenttemplater.php';

        $template = ContentTemplaterHelper::getTemplate($templateId);

        return $template ? $template->introtext : null;
    }
}

Does anyone have experience with this and can already judge if this would work with the code?

BR
Peter van Westen's Avatar Peter van Westen ADMIN
If you need a refund, let me know.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
PS: what you are asking for is outside the scope of what Content Templater is built for.

I recommend you ask help on the Joomla forum. Or try to find someone there that can build what you need.
forum.joomla.org
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription