Skip to content

Instantly share code, notes, and snippets.

@Ticolyle
Last active December 15, 2016 22:30
Show Gist options
  • Select an option

  • Save Ticolyle/685a038cb0f1f7209b9dd50f54b414cd to your computer and use it in GitHub Desktop.

Select an option

Save Ticolyle/685a038cb0f1f7209b9dd50f54b414cd to your computer and use it in GitHub Desktop.

Revisions

  1. Ticolyle revised this gist Dec 15, 2016. 1 changed file with 17 additions and 6 deletions.
    23 changes: 17 additions & 6 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,19 @@
    I’ve taken to moving my macro configuration into a php config file, and then {% set config = craft.config.get('configValue', 'configFile') %} Makes for a more reusable macro, and more commentable config.
    I’ve taken to moving my macro configuration into a php config file, and then `{% set config = craft.config.get('configValue', 'configFile') %}` Makes for a more reusable macro, and more commentable config.

    the twig macro loads the php config file instead of {% set config = {…super complicated thing…} %} You put the super complicated thing in php where it is easier to express

    craft.config.get('configValue', 'configFile') doesn’t need configFile to be an actual plugin
    the twig macro loads the php config file instead of `{% set config = {…super complicated thing…} %}` You put the super complicated thing in php where it is easier to express


    `craft.config.get('configValue', 'configFile')` doesn’t need configFile to be an actual plugin


    in `/craft/config/configFile.php` - and it looks like all the other ones - multiple environments, etc.

    in /craft/config/configFile.php - and it looks like all the other ones - multiple environments, etc.

    ====

    In https://straightupcraft.com/articles/responsive-images-with-twig-macros there is an example of a macro for responsive images. It has this:
    ```
    {% set config = {
    default: {
    srcsetWidths: [400, 800, 1000],
    @@ -26,9 +31,14 @@ In https://straightupcraft.com/articles/responsive-images-with-twig-macros there
    defaultWidth: 200
    }
    } %}
    ```

    Now I would do this in the twig macro:
    `{% set config = craft.config.get('config', 'img') %}`
    And this in `craft/config/img.php`

    `{% set config = craft.config.get('config', 'img') %}`

    And this in `craft/config/img.php
    ```
    <?php
    return array(
    'config' => array(
    @@ -47,3 +57,4 @@ And this in `craft/config/img.php`
    ),
    ),
    );
    ```
  2. Ticolyle created this gist Dec 15, 2016.
    49 changes: 49 additions & 0 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    I’ve taken to moving my macro configuration into a php config file, and then {% set config = craft.config.get('configValue', 'configFile') %} Makes for a more reusable macro, and more commentable config.

    the twig macro loads the php config file instead of {% set config = {…super complicated thing…} %} You put the super complicated thing in php where it is easier to express

    craft.config.get('configValue', 'configFile') doesn’t need configFile to be an actual plugin

    in /craft/config/configFile.php - and it looks like all the other ones - multiple environments, etc.

    ====

    In https://straightupcraft.com/articles/responsive-images-with-twig-macros there is an example of a macro for responsive images. It has this:
    {% set config = {
    default: {
    srcsetWidths: [400, 800, 1000],
    sizes: [
    '(max-width: 30rem) 100vw',
    '25em'
    ],
    defaultWidth: 800
    },
    thumb: {
    srcsetWidths: [200, 400],
    sizes: [
    '200px'
    ],
    defaultWidth: 200
    }
    } %}
    Now I would do this in the twig macro:
    `{% set config = craft.config.get('config', 'img') %}`
    And this in `craft/config/img.php`
    <?php
    return array(
    'config' => array(
    'default' => array(
    'srcsetWidths' => array(400, 800, 1000),
    'sizes' => array(
    '(max-width: 30rem) 100vw',
    '25em'
    ),
    'defaultWidth' => 800
    ),
    'thumb' => array(
    'srcsetWidths' => array(200, 400),
    'sizes' => array('200px'),
    'defaultWidth' => 200
    ),
    ),
    );