1

I am looking to develop a plugin which out put the data in a loop Or that plugin would populate the array data with template tag. Could anyone please help me or share a doc link.

Thanks,

7

Please have a look at the "Template Variables" section of the documentation: http://buildwithcraft.com/docs/plugins/variables

The template variables are the containers of data which you can access from your twig templates using craft.yourPluginName.yourPluginVariableFunctionName

Let's say you want to loop through 3 different items in an array from your Plugin. Your Plugin variables file might look like this:

<?php
namespace Craft;

class PluginNameVariable
{
    public function data()
    {
        return array('one', 'two', 'three');
    }
}

In your template you can now "fetch" this data like this - in a loop:

{% for item in craft.pluginName.data %}
    {{ item }}
{% endfor %}

Please not this code is not tested

| improve this answer | |

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.