Roots Discourse

Tutorial for Acorn

Hi there,

I follow the development of Acorn with great interest. As a Laravel dev I am eager to use Blade and other stuff from Laravel inside a WP Plugin. But how to start? Can someone point me to a Acorn tutorial or sample plugin?

Thanks in advance

Hey @Konafets, thank you for your interest. Acorn is still in development so I don’t think there will be a full fledged tutorial, sample plugin, or a ton of support until the API stabilizes. Until then, here are some pointers:

Acorn itself can either be included as a Composer dependency in a theme or plugin, or be installed as WordPress plugin on which other theme or plugins can depend. If you check out the Acorn plugin file itself, you can see how you’d load it in a dedicated plugin. Similarily, you can check out Sage 10’s functions.php (also in-dev) for an example of how to load it in a theme.

Clover is our Acorn-powered plugin boilerplate. Currently, it’s in early development and is only accessible to Roots’ Patreon subscribers. If you want to try and cobble together a plugin with Acorn, you can check out the Clover related classes within Acorn.

The best way to start using Acorn is either with Sage 10 or with Clover since those are our two tangible examples Acorn being used. Again, the API is subject to change, but a goal is to make it as compatible with many packages originally intended for Laravel. One point of compatibility which is different is that — out of the box — Acorn doesn’t add any of the functions which Laravel does (e.g. app(), view(), etc.), to the global namespace. Acorn does include a filter to enable these global functions:

add_filter('acorn/globals', '__return_true');

So far only key Laravel components (e.g. View/Blade, Filesystem, Database/Eloquent) have been implemented with Acorn. I could imagine others being included incrementally, but I’m not sure if some will translate well inside of a WordPress context.


This topic was automatically closed after 42 days. New replies are no longer allowed.