2017 © Pedro Peláez
 

craft-plugin craft3-beam

Generate CSVs and XLS files in your templates

image

superbig/craft3-beam

Generate CSVs and XLS files in your templates

  • Wednesday, December 13, 2017
  • by superbig
  • Repository
  • 1 Watchers
  • 6 Stars
  • 1,106 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 57 % Grown

The README.md

Beam plugin for Craft CMS 3.x

Generate CSVs and XLS files in your templates, (*1)

Screenshot, (*2)

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later., (*3)

Installation

To install the plugin, follow these instructions., (*4)

  1. Open your terminal and go to your Craft project:, (*5)

    cd /path/to/project
  2. Then tell Composer to load the plugin:, (*6)

    composer require superbig/craft3-beam
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Beam., (*7)

Using Beam

The starting point when working with Beam is to create a instance:, (*8)

{% set options = {
    header: ['Email', 'Name'],
    content: [
        [ 'test@example.com', 'John Doe' ],
        [ 'another+test@example.com', 'Jane Doe' ],
        [ 'third+test@example.com', 'Trond Johansen' ],
    ]
} %}
{% set beam = craft.beam.create(options) %}

This will return a BeamModel behind the scenes., (*9)

If you want to append content dynamically, say from a loop, you can use the append method:, (*10)

{% set myUserQuery = craft.users()
    .group('authors') %}

{# Fetch the users #}
{% set users = myUserQuery.all() %}

{# Display the list #}
{% for user in users %}
    {% do beam.append([user.username, user.name, user.email]) %}
{% endfor %}

To generate an CSV:, (*11)

{% do beam.csv() %}

To generate an XLSX:, (*12)

{% do beam.xlsx() %}

Changing config on the fly

To set the header of the file (the first row):, (*13)

{% do beam.setHeader([ 'Username', 'Name', 'Email' ]) %}

To set the filename:, (*14)

{% set currentDate = now|date('Y-m-d') %}
{% do beam.setFilename('report-#{currentDate}') %}

To overwrite the content:, (*15)

{% do beam.setContent([
    [ 'test@example.com', 'John Doe' ],
    [ 'another+test@example.com', 'Jane Doe' ],
    [ 'third+test@example.com', 'Trond Johansen' ],
]) %}

Brought to you by Superbig, (*16)

The Versions

13/12 2017

dev-master

9999999-dev

Generate CSVs and XLS files in your templates

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft beam

01/11 2017

2.0.0

2.0.0.0

Generate CSVs and XLS files in your templates

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft beam