# Including ACF Pro in fork of sage theme: where to store key?

**URL:** https://discourse.roots.io/t/including-acf-pro-in-fork-of-sage-theme-where-to-store-key/18265
**Category:** sage
**Tags:** composer, sage10
**Created:** 2020-05-15T13:11:57Z
**Posts:** 7

## Post 1 by @drbroad — 2020-05-15T13:11:57Z

I have a full Trellis/Bedrock/Sage setup, where I have forked the Sage theme to customize it to our needs.

The theme is so dependent on ACF Pro, that it makes more sense for me to include it in the theme. My first thought was that the theme composer.json might be able to read the .env file in the site directory but so far, I haven’t found a way to load that from a different folder.

Is my only other option to include the ACF code in my fork and manually update it in the fork anytime ?

Ideally id like to work out an env solution that doesn’t require me to bundle the code with the theme. Does anyone have any smart ideas on how I might do this?

---

## Post 2 by @strarsis — 2020-05-15T15:45:46Z

For development I store the ACF PRO key in the `.env` file (WordPress [roots.io](http://roots.io) Bedrock setup),  
for production I store the ACF PRO in `vault.yml` ([roots.io](http://roots.io) Trellis system).

For installing ACF PRO vis composer (independent from environment) I use  
[`ffraenz/private-composer-installer`](https://packagist.org/packages/ffraenz/private-composer-installer).

---

## Post 3 by @drbroad — 2020-05-15T15:48:10Z

I appreciate the reply, but I think you have missed my point.

I understand (and use often) the env file for the ACF key when bundling ACF pro in the site folder composer.json.

What I want to do, is move ACF from being a dependency of the Bedrock setup, to being a dependency of the theme itself. And the theme composer.json cannot reach back up to read the .env file in the site folder.

---

## Post 4 by @strarsis — 2020-05-15T15:50:45Z

Do you want to sell the theme with ACF PRO (or bundle it)?  
See this post from the ACF site:

> **[ACF | Including ACF within a plugin or theme](https://www.advancedcustomfields.com/resources/including-acf-within-a-plugin-or-theme/)**
>
> Introduction The Advanced Custom Fields plugin is a powerful tool for developing bespoke websites and web-apps. Although designed primarily for individual

  
Section [How to include plugin files](https://www.advancedcustomfields.com/resources/including-acf-within-a-plugin-or-theme/#how-to%20include%20plugin%20files).

---

## Post 5 by @drbroad — 2020-05-15T17:26:00Z

Yes, i have explored that, and thats easy to do, but not what im trying to achieve.

Ill try to clarify: I want to **avoid bundling the acf plugin code in the repo** itself, and would prefer to use composer to install, but inside the theme and not from the site folder.

Looks like i may have to just bundle it, or let bedrock handle it.

---

## Post 6 by @strarsis — 2020-05-15T18:10:33Z

This would be a build step then. For trellis deploy, by default a deploy hook runs and invokes `composer install` for the bedrock site (`composer.json` with the plugins).  
In your case with the theme you would also want to invoke `composer install` _in the theme directory_,  
so you add an invocation to `composer install` to the deploy hook, but with the theme directory as cwd.

---

## Post 7 by @alwaysblank — 2020-05-15T20:56:19Z

If your theme is never going to be used outside of the Roots stack, I’m not sure why it matters whether ACF is a dependency of your theme or your site. If your site is going to be used outside of the scope of the Roots stack, you have a different problem to solve in terms of where your key will be stored so you can either distribute or reliably deploy the theme.

AFAIK you should be able to put a `.env` file in your theme root and then use `ffraenz/private-composer-installer` in your theme as you would in your site. Obviously you don’t want to commit that `.env` to your theme, so if you’re deploying w/ Trellis you could use use `deploy-hooks/build-before.yml` to generate a new `.env` in your theme folder, ala:

```
- name: Create theme .env
  template:
    src: "{{ playbook_dir }}/deploy-hooks/.env.j2"
    dest: "{{ deploy_helper.new_release_path }}//web/app/themes/your-theme/.env"
    mode: "0600"
```

_Another_ approach would be to fork `ffraenz/private-composer-installer` and point it to your site `.env`. Changing this would probably do it: [https://github.com/ffraenz/private-composer-installer/blob/296dae1d51e826978008962fd6ece1612c2eaeb7/src/PrivateComposerInstaller/Plugin.php#L36-L39](https://github.com/ffraenz/private-composer-installer/blob/296dae1d51e826978008962fd6ece1612c2eaeb7/src/PrivateComposerInstaller/Plugin.php#L36-L39) It seems a little weird to me to have your theme dependency dependant on the existance of something (the `.env`) in the site, though.

---

## Post 8 by @system — 2020-06-26T13:11:59Z

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