1

I'd like to send a formatted HTML email from a custom component. I thought I would be able to create a tmpl file somewhere like components/mycomponent/views/emailer/tmpl/default_email.php and then in the view (at components/mycomponent/views/emailer/view.email.php) I'd be able to render the default_email view with the data pulled from the model and then send it.

It appears the "normal" Joomla way is to do a sprintf with a language string to generate the email.

Is there no way to render the template file in the view prior to sending the email?

1

Yes, there are several ways to render internally a page from a view.

Basically, you call the view and capture the output in a variable.

For instance, in FoF you can do it in this way:

    ob_start();
    F0FDispatcher::getTmpInstance(
            'com_mycomponent',
            'theview',
            $config
        )->dispatch();
    $output = ob_get_contents();
    ob_end_clean();

You can also call the Url with a cURL connection, but it is slower since you must open a new network connection to render the page.

  • @Anibal-- will this render the complete template including menu items etc? Or will it just render the single template item? – user101289 Mar 9 '16 at 16:08
  • 1
    Hi, this sample code renders only a component view. If you go for the alternative calling a page via an Url, you'll get the whole page. – Anibal Mar 9 '16 at 16:33
  • @anibal- how do you specify the specific tmpl file to render? Could you please provide more detail on the specific usage in your answer? – user101289 Mar 11 '16 at 5:22
  • Joomla and Fof render tmpl/default.php. If you have other layouts, then you can specify parameters in $config. – Anibal Mar 11 '16 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.