Last active
December 15, 2016 22:30
-
-
Save Ticolyle/685a038cb0f1f7209b9dd50f54b414cd to your computer and use it in GitHub Desktop.
Revisions
-
Ticolyle revised this gist
Dec 15, 2016 . 1 changed file with 17 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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. 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], @@ -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 ``` <?php return array( 'config' => array( @@ -47,3 +57,4 @@ And this in `craft/config/img.php` ), ), ); ``` -
Ticolyle created this gist
Dec 15, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ), ), );