How to render a macro from a plugin? Im trying to render a site macro from my plugin, i’m getting the following error:

Argument 1 passed to Twig_Template::display() must be of the type array, object given, called in /path/to/file.php on line 51 and defined in "_macros/elements" at line 3


My service contains the following method:

public function renderSiteMacro($template, $macro, array $args)
{
    // Get the current template path
    $originalPath = craft()-&gt;path-&gt;getTemplatesPath();

    // Point Twig at the site templates
    craft()-&gt;path-&gt;setTemplatesPath(craft()-&gt;path-&gt;getSiteTemplatesPath());

    // Render the macro.
    $html = craft()-&gt;templates-&gt;renderMacro($template, $macro, $args);

    // Restore the original template path
    craft()-&gt;path-&gt;setTemplatesPath($originalPath);

    return TemplateHelper::getRaw($html);
}


And i'm calling it as follows:

$args = array(
    'entry' =&gt; $user,
    'layout' =&gt; 'friend'
);

$userHtml = craft()-&gt;logic-&gt;renderSiteMacro('_macros/elements', 'listing', $args);


The issue appears to be with the include line in my macro template file:

{% macro listing(config) %}
{% include "_macros/elements/listing" with config only %}
{% endmacro %}


Does anyone know what i'm missing?
The format of the include tag is

{% include 'template' with {var1: value1, var2: value2} only %}


What you need after the with is an associative array (an array with keys and values).

In your specific case you want this:

{% include "_macros/elements/listing" with {config: config} only %}