Giter Site home page Giter Site logo

nystudio107 / eagerbeaver Goto Github PK

View Code? Open in Web Editor NEW
25.0 5.0 1.0 40 KB

DEPRECATED Allows you to eager load elements from auto-injected Entry elements on demand from your templates.

License: MIT License

PHP 100.00%
craftcms craft-plugin eager-loading elements

eagerbeaver's Introduction

No Maintenance Intended

DEPRECATED

This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.

The Craft CMS 3.x version of this plugin can be found here: craft-eagerbeaver and can also be installed via the Craft Plugin Store in the Craft CP.

Eager Beaver plugin for Craft CMS

Allows you to eager load elements from auto-injected Entry elements on demand from your templates.

Screenshot

Related: Eager Beaver for Craft 3.x

Installation

To install Eager Beaver, follow these steps:

  1. Download & unzip the file and place the eagerbeaver directory into your craft/plugins directory
  2. -OR- do a git clone https://github.com/nystudio107/eagerbeaver.git directly into your craft/plugins folder. You can then update it with git pull
  3. -OR- install with Composer via composer require nystudio107/eagerbeaver
  4. Install plugin in the Craft Control Panel under Settings > Plugins
  5. The plugin folder should be named eagerbeaver for Craft to see it. GitHub recently started appending -master (the branch name) to the name of the folder for zip file downloads.

Eager Beaver works on Craft 2.6.x.

Eager Beaver Overview

Craft's Eager-Loading Elements allows you to nicely optimize your templates by telling Craft to load everything you need in one big query.

The only rub is that you can't specify this eager loading behavior for entry, category, or product elements that are auto-injected into your template.

Eager Beaver is a small plugin that allows you to eager load sub-elements like Assets, Categories, Users, etc. to these auto-injected elements.

This is especially useful if you have pages that use Matrix block "content builders", and thus will typically result in loading a number of relations like Assets contained in Matrix blocks to render a page.

Configuring Eager Beaver

There's nothing to configure.

Using Eager Beaver

To use Eager Beaver, simply do something like:

{% do eagerLoadElements(entry, [
    'author.userPicture',
    'blogCategory',
    'blogImage',
    'blogContent.image:image'
]) %}

Or you can use the more verbose syntax to do the same thing:

{% do craft.eagerBeaver.eagerLoadElements(entry, [
    'author.userPicture',
    'blogCategory',
    'blogImage',
    'blogContent',
    'blogContent.image:image'
]) %}

The first parameter is the Element or array of Elements that you want to eager-load sub-elements into, such as an entry. If you pass in an array of Elements, they must all be the same type.

The second parameter is the same with: that you use for Eager-Loading Elements, and uses the exact same syntax.

In the above example:

  • author is a User that has an Assets field named userPicture added to it.
  • blogCategory is a Category field
  • blogImage is an Asset field
  • blogContent is a Matrix field that has an Assets field named image added to the block type image

Eager Beaver Roadmap

Some things to do, and ideas for potential features:

  • Release it

Brought to you by nystudio107

eagerbeaver's People

Contributors

khalwat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

seanpm2001

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.