Is it possible to return data/models from controller to template via setRouteVariables? I'm trying to write a plugin that lives in the admin interface, that reads external data (a cinema program), parses it, and creates entries based on this (movie info and screening times).

While doing so I build a log of the additions/updates made, that I want to return to the template (the plugin page from where I trigger the update) and display the changes listed in a table. But I have trouble reading anything out with craft.request.getPost() from the template.

The log, basically an array of custom models (log items), seems to be fine while still in the controller. I try to pass this array via craft()-&gt;urlManager-&gt;setRouteVariables(), but at the template, it seems the only variables it finds are the action and redirect parameters from the original form.

The code in the controller looks like this:

$log = craft()-&gt;updateProgram_program-&gt;update();
craft()-&gt;urlManager-&gt;setRouteVariables(array(
   'log' =&gt; $log
));


And then I try to read the log variable in my template like this:

{% set log = craft.request.getPost('log') %}


Whatever I do, it seems to always be NULL. I've also tried to set a simple text string as the value, in case it's not possible to post an array like this, but it's still NULL when it comes to the template. It seems the log parameter is simply not found in the POST request at all.

Is there anything obvious I'm doing wrong?

I've scratched my head all day over this, so any tips are extremely welcome!
I believe you are overwriting the log variable you are sending back to the template when you set log equal to the response of getPost.

From what I can see of your code, when you return variables to your template via setRouteVariables, you should be providing the variables you define in that array to your template, without having to take a second step and retrieve them.  So, when your controller returns:

craft()-&gt;urlManager-&gt;setRouteVariables(array(
   'log' =&gt; $log
));


You should then be able to access that variable in your template if it exists:

{% if log is defined %}
    {{ dump(log) }}
{% endif %}




setRouteVariables adds your variables to Twig's context, which you can see in your template by dumping _context:

{{ dump(_context) }}


Or, a handy way to just see the variables available in the context and not the full models is using the keys filter:

{{ dump(_context|keys) }}




In your case, I believe when your page reloads, your log variable is available, but then you set it to null when you try to retrieve it.

Your current code:

{# Sets log to null, because no post variable exists named `log` #}
{% set log = craft.request.getPost('log') %}

{% if log is defined %}
    {{ dump(log) }} {# outputs null #}
{% endif %}


Try outputting the log variable before setting your getPost value:

{# Outputs log if it exists in Twig's context #}
{% if log is defined %}
    {{ dump(log) }} {# will probably output your value #}
{% endif %}

{# Delete this. It just overwrites your existing log variable #}
{% set log = craft.request.getPost('log') %}