Popular Pages

Our Work

See some of our best, most challenging projects.

Craft CMS

We're Craft CMS experts (and an Official Partner).

Introducing the Lab Reports Plugin for Craft CMS

Benjamin Kohl Oct 12, 2021 Read time: 2 minute read
Lab reports header

The Lab Reports plugin for Craft CMS provides developers with the ability to configure and execute custom, routine reports/exports on behalf of their clients.

We have numerous clients that request the ability to periodically export various portions of their content as CSV files. Craft provides a native element export tool that appears at the bottom of every element index page in the control panel, but the generated CSV files contain far more columns than our clients need and the resulting values are often limited to their respective database column values, which doesn’t always suit our clients’ needs.

For example, a site may contain a single Checkboxes field to store a user’s email communication preferences. The client would like a users CSV export formatted in such a way that each checkbox option has its own column with a simple “yes” or “no” value that represents whether or not the user has opted to receive those particular communications. In order to accomplish that, we need a custom reporting/exporting tool.

We previously used another third-party option to construct such exports but the plugin went through a long period of instability that resulted in some of our clients’ control panels crashing entirely without any kind of intervention. We couldn’t have that! Additionally, the plugin struggled or failed entirely when generating CSVs with thousands and thousands of rows and many of our clients’ sites have an extraordinary amount of content. We had to do something to give our clients what they needed without breaking their mission-critical websites.

That’s why we came up with the idea for Lab Reports. We wanted to create a custom reporting/exporting tool that felt familiar, but could handle very large datasets without causing the control panel to hang or crash.

The report configurations are not limited to any particular Craft element type or database table. Basic report queries are configured via Twig templates using syntax all Craft developers are familiar with. For larger datasets, we recommend using an Advanced report configuration which requires a little bit of PHP knowledge but examples are provided with the plugin.

Reports can be generated manually from the control panel or they can be generated on a schedule via cron jobs. Lab Reports keeps a complete history of every report generated and provides administrative users with download links in the control panel.

The formats of the various CSV column values are left entirely up to the client/developer. If someone requests a column containing an entry title rather than its ID, that’s not a problem for Lab Reports! Check out how easy it is to configure a Basic export of entry content in the example below:

{# Initialize the rows with the column headers. #}
{% set rows = [[
    'Date Created',
    'Cover Image',
    'Publish Year',
]] %}

{# Construct a query and execute it. #}
{% set entries = craft.entries.section('books')
    .orderBy('title').all() %}

{# Loop through the entries and add them to the report. #}
{% for entry in entries %}
    {% set coverImage = entry.coverImage[0] ?? null %}
    {% set coverImageUrl = coverImage ? coverImage.url : null %}
    {% set rows = rows|merge([[
        entry.dateCreated|date('F J, Y g:i A'),
    ]]) %}
{% endfor %}

{# Tell Lab Reports to construct the CSV file and save the report record. #}
{% do report.build(rows) %}

If you need the ability to construct and execute customized, routine CSV content exports of any size for your client, consider checking out Lab Reports in the Craft Plugin Store.

Subscribe to our newsletter!

A few times a year we send out a newsletter with tips and info related to Craft CMS, technical SEO, and things we find interesting. No spam. Unsubscribe any time.

You Might Also Like

How to Use Vue.js on Pre-Rendered Forms

Using Vue.js with Server Rendered Form Input Values

Masuga Design
Catherine K. Sep 10, 2021  ·  4 minute read

Vue.js is great for interactive forms, and updating page contents based on user interaction with a form. But Vue.js isn't so great for forms with input values already rendered from the server. We'll look at how to get around that roadblock.

PageSpeed Insights Core Web Vitals

Improving Google Page Experience With Core Web Vitals

Ryan Masuga Aug 31, 2021  ·  12 minute read

Overall website performance has always been important but after Google's Page Experience updates in 2021, it's more important than ever. Improving your site's Core Web Vitals can drastically improve the page experience for your site visitors.