Skip to content

Support for multi-environment variables #14

Closed

Description

@haabe

The project's location in my staging environment and production environment differs, so I cannot hardcode the full path within the Buttonbox config. I wish to use multi-environment variables, as described in the Craft CMS docs.

I have a multi-environment variable called basePath, which points to the project's root folder (some/folder/to/project/craft) on my staging server. On my production server, the path might differ (some/other/folder/to/project/craft).

When using multi-environment variables, as described in the docs, Buttonbox just urlencodes the variable. Let's say my general.php says that 'baseUrl' => 'http:/www.some.site/some/folders/to/project'. So when I enter {baseUrl}/admin/resources/images/icon.png, it should render http:/www.some.site/some/folders/to/project/admin/resources/images/icon.png. But it renders it as %7BbaseUrl%7D/admin/resources/images/icon.png.

Activity

  1. haabe commented on Oct 3, 2017

    @haabe
    Author

    Here's what I did to buttonbox/templates/buttons/field.html:

          {% if option.imageUrl %}
            {% if option.imageUrl matches '/{[^}]*}/' %}
              {% set envVariable = option.imageUrl | replace('/.*{([^}]*)}.*/', '$1') %}
              {% set envVariable = craft.config.environmentVariables[envVariable] %}
              {% set envImageUrl = option.imageUrl | replace('/{[^}]*}/', envVariable) %}
            {% endif %}
          <img src="{{ envImageUrl ?? option.imageUrl }}"{% if option.showLabel %} class="buttonbox-buttons__with-label"{% endif %} {% if not option.showLabel %} title="{{ optionLabel }}"{% endif %} />
          {% endif %}
    
  2. Nav33d commented on Oct 3, 2017

    @Nav33d
    Contributor

    Hi Haabe,

    You don't need to provide full path to the project. You can have your icons saved in public folder. Lets say you have your icons saved in a files folder within public folder, then the path to the icon would be /files/icon.png. It would work regardless of your different environments setup.

    Hope that helps.

    Many thanks

  3. haabe commented on Oct 3, 2017

    @haabe
    Author

    Yeah, well our different server setups make use of the public root folder difficult, whereas we've been using the multi-environment variables.

    I've provided you with an example code on how to handle it. It'd be nice to see it implemented.

  4. Nav33d commented on Oct 5, 2017

    @Nav33d
    Contributor

    Hi,

    We will definitely support environment specific variables in the future but I'm afraid won't be straight away as we have triggers field using URLs too.

    In the meantime, you could fork this repo and implement your solution as a temporary fix.

    Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions