Halland π²
Halland is a Wordpress theme built by Region Halland, based on Sage., (*1)
View theme structure
, (*2)
<, (*3)
p>, (*4)
themes/halland/ # β Root
βββ app/ # β Theme PHP
β βββ Acf/ # β ACF Fields
β βββ controllers/ # β Controller files
β βββ Theme/ # β Enqueue files, register sidebars
β βββ Traits/ # β Traits used in the theme
β βββ admin.php # β Theme customizer setup
β βββ filters.php # β Theme filters
β βββ helpers.php # β Helper functions
β βββ setup.php # β Theme setup
βββ composer.json # β Autoloading for `app/` files
βββ composer.lock # β Composer lock file (never edit)
βββ dist/ # β Built theme assets (never edit)
βββ node_modules/ # β Node.js packages (never edit)
βββ package.json # β Node.js dependencies and scripts
βββ resources/ # β Theme assets and templates
β βββ assets/ # β Front-end assets
β β βββ config.json # β Settings for compiled assets
β β βββ build/ # β Webpack and ESLint config
β β βββ fonts/ # β Theme fonts
β β βββ images/ # β Theme images
β β βββ scripts/ # β Theme JS
β β βββ styles/ # β Theme stylesheets
β βββ functions.php # β Composer autoloader, theme includes
β βββ index.php # β Never manually edit
β βββ screenshot.png # β Theme screenshot for WP admin
β βββ style.css # β Theme meta information
β βββ views/ # β Theme templates
β βββ layouts/ # β Base templates
β βββ partials/ # β Partial templates
βββ vendor/ # β Composer packages (never edit)
<, (*5)
p>
, (*6)
Requirements
Getting started
- Clone Halland into the themes directory of your Wordpress installation and install dependencies:
$ cd <your site>/web/app/themes/
$ git clone https://github.com/RegionHalland/halland.git
$ cd halland
$ composer install && yarn
- Update
resources/assets/config.json
settings:
- devUrl
should reflect your local development hostname, for example http://site.test
- publicPath
should reflect your WordPress directory structure (/web/app/themes/halland
or /wp-content/themes/halland
for non-Bedrock installs), (*7)
- Build commands
* yarn start
β Compile assets when file changes are made, start Browsersync session
* yarn build
β Compile and optimize the files in your assets directory
* yarn build:production
β Compile assets for production, (*8)
Styleguide
Almost all of the CSS on the front-end is defined in our styleguide. Halland uses it by looking for the environment variable COMPONENT_LIBRARY_URI
. If the variable can't be found, Halland defaults to the styleguide published on Github Pages., (*9)
If you want to work with CSS, set up up a local version of the styleguide by following the instructions in it's repo and make your changes there., (*10)
CORS
Allow requests to your local version of the styleguide by adding the following headers to it's nginx config:, (*11)
- SSH into your Homestead server and edit the styleguides nginx config:
$ cd ~/Homestead
$ homestead ssh
$ sudo nano /etc/nginx/sites-enabled/styleguide.test
- Place the headers in the server block of the nginx config:
# Allow CORS
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
- Reload the nginx config.
$ sudo service nginx reload
ACF Fields
Halland uses Advanced Custom Fields to create custom fields and ACF Export Manager to save the field definitions as .php
and .json
files, so that we can keep them under version control., (*12)
Importing
The field definitions are imported automatically with ACF Export Manager. The export manager will automatically import all field groups defined in /halland/Acf/Import.php
., (*13)
To be imported, they must first be exported by following the instructions below. ‡οΈ, (*14)
Exporting
-
Create your field group in the Wordpress admin panel like you normally would under Fields β Add new., (*15)
-
Over the Save / Publish button to the right, you will find your field groups unique ID. It looks something like group_5b716c7b279da
. Copy the field groups ID and add it to the array defined in /halland/Acf/Import.php
:, (*16)
$acfExportManager->autoExport(array(
...
...
'my-new-fieldgroup' => 'group_5b716c7b279da'
));
-
Save / Publish your field group and ACF Export Manager will create a
.php
and a .json
file for your new field group in each respective folder. Make sure to commit these files.
Editing existing field groups
-
First of you need to identify the filename of the field group you want to edit. The easiest way to do this is probably to look at the key-value pairs found in the import array in /halland/Acf/Import.php
., (*17)
-
For minor changes you can edit the field groups directly in code. Remember to edit both the .json
and the .php
files found in /halland/Acf/<json or php>/my-new-field-group.<json or php>
., (*18)
-
For bigger changes you might want to use the admin panels interface. Go to Fields β Tools and import your field groups .json
file (found in /halland/Acf/json/my-new-field-group.json
)., (*19)
-
Edit your field group. When you Save / Publish, the changes will automatically be exported to code. Commit your changes! π€, (*20)
Child themes
TBD, (*21)