Skip to content

Adding a controller #19

Description

@broskees

I'd really like to place a controller between the component and the template, for example:

{# /components/templates/table.twig #}
{% spaceless %}
    <table {{ attributes.merge({}) }}>
        {% if caption is not empty %}
            <caption {{ caption.attributes }}>
              {{ caption }}
            </caption>
        {% endif %}
        {% for row in rows %}
            <tr {{ row.attributes.merge({}) }}>
                {% for cell in column %}
                    <{{ cell.type }} {{ cell.attributes.merge({}) }}>{{ cell.label ?: '&nbsp;' }}</{{ cell.type }}>
                {% endfor %}
            </tr>
        {% endfor %}
    </table>
{% endspaceless %}
<?php
/**
 * /components/controllers/table.php
 */
 
class table
{
  public function __construct($attributes)
  {
    if (!isset($attributes['caption']) {
      throw new Error("You must define a caption to keep this accessible");
    }
  }
}

Is there any way to implement something like this with this library?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions