Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_many inside block? #66

Closed
jacobsjensen opened this issue Feb 26, 2016 · 0 comments
Closed

has_many inside block? #66

jacobsjensen opened this issue Feb 26, 2016 · 0 comments

Comments

@jacobsjensen
Copy link

Hi,

Ive got this block called EmployeesBlock, in which I want to create multiple employees.
For some reason I can't get it to loop the Employees in the code... Is there anything I'm doing wrong in relation to having a loop inside a Block ?

EmployeesBlock.php

<?php

class EmployeesBlock extends Block {
    private static $db = array (
    );

    private static $has_one = array (
    );

    private static $has_many = array (
        "Employees" => "Employee"
    );


public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        // Viewer groups
        $fields->removeFieldFromTab('Root', 'ViewerGroups');
        return $fields;
    }

}

Employee.php

<?php

class Employee extends DataObject {
    private static $db = array (
        'Text' => 'HTMLText'
            );

    private static $has_one = array (
        'Image' => 'Image',
        'EmployeesBlock' => 'EmployeesBlock'
    );


public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab("Root.Main", UploadField::create('Image', 'Employee image'));
        $fields->addFieldToTab("Root.Main", HTMLEditorField::create('Text', 'Employee text')->setRows(3));
        return $fields;
    }

}

EmployeesBlock.ss

<% loop $Employees %>
    <div class="employee <% if $Odd %>uPullLeft<% else %>uPullRight<% end_if %>">
        <div class="employeeImage">
            <img src="$Image.URL" alt="" class="uFullWidth" />
        </div>
        <div class="employeeText">$Text</div>
    </div>
<% end_loop %>
sheadawson added a commit that referenced this issue Feb 28, 2016
* master:
  revert rendering of Block back to using Block DataObject. Fixes #66
  Remove trailing spaces in the source code
  Adding default Scrutinizer config for CI
  Fixing composer.json
  Adding default Travis config for testing
  Block Type Filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant