-1

I just build my first plugin with OctoberCMS Builder Plugin. I'm having trouble when I try to show the plugin data on the front-end.

I have created a component, but there is some code missing in the component.php and default.htm. I don't know which values to use when reading the documentation cause my technical English is not so good.

This is the last piece I would like to learn so I can build my own plugins, can someone help me out please? Here is the link to the plugin:

https://github.com/Hessel91/activiteiten

P.s: I know how to output the data with the builder component but I would like to learn how to do it with my own component.

1 Answers1

0

In your component it is missing onRender method which is used for setting data to page and then you can access it in view default.htm

in your component activiteiten/hessel/activiteiten/components/Activiteit.php

public function onRender()
{    
    $this->page['records'] = \SomeModel::find();
    // $this->page['records'] = $this->someData();
}

// OR MAY BE THIS

public function someData()
{    
    return [
        ['name' => 'hardik'], 
        ['name' => 'hitesh'],
        ['name' => 'new name'],
    ];
}

and inside partial activiteiten/hessel/activiteiten/components/activiteit/default.htm you can use this code

{% for record in records %}
    <h1>{{ record.title }}</h1>        
{% endfor %}

<!-- OR MAY BE THIS -->

{% for item in __SELF__.someData() %}
    <h1>{{ item.name}}</h1>        
{% endfor %}

For suggestion you need to read this document:

https://octobercms.com/docs/plugin/components

if you find any issue please comment.

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40
  • Thank you for your explanation Hardik, however, I don't know what records to fill in. I'm sorry for asking but can you upload the correct component file to the GitHub directory because I can't figure it out, I'm sorry. – Hessel Kers Mar 09 '18 at 22:23