Use prism for code syntax highlighting

This commit is contained in:
Oliver Davies 2017-03-16 08:09:52 +00:00
parent 356c9dca43
commit adf3c67355
54 changed files with 471 additions and 324 deletions

View file

@ -1,9 +1,12 @@
pre pre
display: block
overflow: auto overflow: auto
word-break: normal
word-wrap: no-wrap word-wrap: no-wrap
pre code pre code
white-space: pre white-space: pre
word-break: normal
code.hljs code.hljs
background-color: inherit background-color: inherit

View file

@ -5,6 +5,6 @@
"compass-breakpoint": "breakpoint-sass#~2.6.1", "compass-breakpoint": "breakpoint-sass#~2.6.1",
"font-awesome": "fontawesome#~4.5.0", "font-awesome": "fontawesome#~4.5.0",
"jquery2": "^2.0.0", "jquery2": "^2.0.0",
"highlightjs": "^9.9.0" "prism": "prismjs#^1.6.0"
} }
} }

View file

@ -23,7 +23,7 @@ var config = {
gulp.task('styles', function() { gulp.task('styles', function() {
return gulp.src([ return gulp.src([
config.bowerDir + '/font-awesome/css/font-awesome.css', config.bowerDir + '/font-awesome/css/font-awesome.css',
config.bowerDir + '/highlightjs/styles/default.css', config.bowerDir + '/prism/themes/prism-tomorrow.css',
config.sass.sourceDir + config.sass.pattern config.sass.sourceDir + config.sass.pattern
]) ])
.pipe(plugins.plumber()) .pipe(plugins.plumber())
@ -50,7 +50,8 @@ gulp.task('scripts', function() {
return gulp.src([ return gulp.src([
config.bowerDir + '/jquery2/jquery.js', config.bowerDir + '/jquery2/jquery.js',
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js', config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js',
config.bowerDir + '/highlightjs/highlight.pack.js', config.bowerDir + '/prism/prism.js',
config.bowerDir + '/prism/components/prism-{apacheconf,bash,css,ini,json,nginx,php,sass,scss,sql,less,twig,xml,yaml}.js',
config.js.sourceDir + config.js.pattern config.js.sourceDir + config.js.pattern
]) ])
.pipe(plugins.plumber()) .pipe(plugins.plumber())

View file

@ -14,19 +14,19 @@ To start with, I wanted to have something that described what the list was displ
I scrolled down until I found the piece of code that displayed the terms list: I scrolled down until I found the piece of code that displayed the terms list:
~~~php ```language-php
<?php if ($terms): ?> <?php if ($terms): ?>
<div class="terms terms-inline"> <div class="terms terms-inline">
<?php print t('Posted in') . $terms; ?> <?php print t('Posted in') . $terms; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
~~~ ```
Adding `print t(' Posted in ')` will print the words 'Posted in' before outputing the terms. Adding `print t(' Posted in ')` will print the words 'Posted in' before outputing the terms.
I then added some CSS to re-size the spacing between the items, and then add the commas between them to seperate them: I then added some CSS to re-size the spacing between the items, and then add the commas between them to seperate them:
~~~css ```language-css
.terms ul.links li { .terms ul.links li {
margin-right: 1px; margin-right: 1px;
padding: 0; padding: 0;
@ -39,22 +39,22 @@ I then added some CSS to re-size the spacing between the items, and then add the
.terms ul.links li.last:after { .terms ul.links li.last:after {
content: "."; content: ".";
} }
~~~ ```
I created a file named **script.js** in my theme folder with the following code in it. After clearing Drupal's caches, this file is automatically recognised by Drupal 6. I created a file named **script.js** in my theme folder with the following code in it. After clearing Drupal's caches, this file is automatically recognised by Drupal 6.
~~~js ```language-js
if (Drupal.jsEnabled) { if (Drupal.jsEnabled) {
$(document).ready(function() { $(document).ready(function() {
$('.terms ul.links li.last').prev().addClass('test'); $('.terms ul.links li.last').prev().addClass('test');
}) })
} }
~~~ ```
This code finds the last item in the list, uses **.prev** to select the one before it, and then uses **.addClass** to assign it the HTML class of "test". We can then use this class to target it with specific CSS. This code finds the last item in the list, uses **.prev** to select the one before it, and then uses **.addClass** to assign it the HTML class of "test". We can then use this class to target it with specific CSS.
~~~css ```language-css
.terms ul.links li.test:after { .terms ul.links li.test:after {
content: " and"; content: " and";
} }
~~~ ```

View file

@ -10,7 +10,9 @@ use: [posts]
--- ---
I created a new Webform to serve as a simple Contact form, but left the main configuration until after I created the form components. I added 'Name', 'Email', 'Subject' and 'Message' fields, as well as a 'Category' select list. Below 'Options', I entered each of my desired options in the following format: I created a new Webform to serve as a simple Contact form, but left the main configuration until after I created the form components. I added 'Name', 'Email', 'Subject' and 'Message' fields, as well as a 'Category' select list. Below 'Options', I entered each of my desired options in the following format:
Email address|Visible name ```language-ini
Email address|Visible name
```
I went back to the form configuration page and expanded 'Conditional Email Recipients', and selected my Category. Note that the standard 'Email To' field above it needs to be empty. Originally, I made the mistake of leaving addresses in that field which resulted in people being sent emails regardles of which category was selected. I then configured the rest of the form. I went back to the form configuration page and expanded 'Conditional Email Recipients', and selected my Category. Note that the standard 'Email To' field above it needs to be empty. Originally, I made the mistake of leaving addresses in that field which resulted in people being sent emails regardles of which category was selected. I then configured the rest of the form.

View file

@ -19,8 +19,8 @@ I added the dimensions of my images, the type of animation, specified the node t
I added the following code into my About page, as described in the Fancy Slide readme.txt file - the number representing the ID of the slideshow. I added the following code into my About page, as described in the Fancy Slide readme.txt file - the number representing the ID of the slideshow.
~~~php ```language-php
<?php print theme('fancy_slide', 1); ?> <?php print theme('fancy_slide', 1); ?>
~~~ ```
In my opinion, this adds a nice effect to the About page. I like it because it's easy to set up, and easy to add additional images later on if required. In my opinion, this adds a nice effect to the About page. I like it because it's easy to set up, and easy to add additional images later on if required.

View file

@ -20,21 +20,21 @@ I didn't want to manually open each post and add the new tag, so I decided to ma
The first thing I did was create the 'Drupal Planet' term in my Tags vocabulary. I decided to do this via the administration area of my site, and not via the database. Then, using [Sequel Pro](http://www.sequelpro.com), I ran the following SQL query to give me a list of Blog posts on my site - showing just their titles and nid values. The first thing I did was create the 'Drupal Planet' term in my Tags vocabulary. I decided to do this via the administration area of my site, and not via the database. Then, using [Sequel Pro](http://www.sequelpro.com), I ran the following SQL query to give me a list of Blog posts on my site - showing just their titles and nid values.
~~~sql ```language-sql
SELECT title, nid FROM node WHERE TYPE = 'blog' ORDER BY title ASC; SELECT title, nid FROM node WHERE TYPE = 'blog' ORDER BY title ASC;
~~~ ```
I made a note of the nid's of the returned nodes, and kept them for later. I then ran a similar query against the term_data table. This returned a list of Taxonomy terms - showing the term's name, and it's unique tid value. I made a note of the nid's of the returned nodes, and kept them for later. I then ran a similar query against the term_data table. This returned a list of Taxonomy terms - showing the term's name, and it's unique tid value.
~~~sql ```language-sql
SELECT NAME, tid FROM term_data ORDER BY NAME ASC; SELECT NAME, tid FROM term_data ORDER BY NAME ASC;
~~~ ```
The term that I was interested in, Drupal Planet, had the tid of 84. To confirm that no nodes were already assigned a taxonomy term with this tid, I ran another query against the database. I'm using aliases within this query to link the node, term_node and term_data tables. For more information on SQL aliases, take a look at <http://w3schools.com/sql/sql_alias.asp>. The term that I was interested in, Drupal Planet, had the tid of 84. To confirm that no nodes were already assigned a taxonomy term with this tid, I ran another query against the database. I'm using aliases within this query to link the node, term_node and term_data tables. For more information on SQL aliases, take a look at <http://w3schools.com/sql/sql_alias.asp>.
~~~sql ```language-sql
SELECT * FROM node n, term_data td, term_node tn WHERE td.tid = 84 AND n.nid = tn.nid AND tn.tid = td.tid; SELECT * FROM node n, term_data td, term_node tn WHERE td.tid = 84 AND n.nid = tn.nid AND tn.tid = td.tid;
~~~ ```
As expected, it returned no rows. As expected, it returned no rows.
@ -42,9 +42,9 @@ The table that links node and term_data is called term_node, and is made up of t
To confirm everything, I ran a simple query against an old post. I know that the only taxonomy term associated with this post is 'Personal', which has a tid value of 44. To confirm everything, I ran a simple query against an old post. I know that the only taxonomy term associated with this post is 'Personal', which has a tid value of 44.
~~~sql ```language-sql
SELECT nid, tid FROM term_node WHERE nid = 216; SELECT nid, tid FROM term_node WHERE nid = 216;
~~~ ```
Once the query had confirmed the correct tid value, I began to write the SQL Insert statement that would be needed to add the new term to the required nodes. The nid and vid values were the same on each node, and the value of my taxonomy term would need to be 84. Once the query had confirmed the correct tid value, I began to write the SQL Insert statement that would be needed to add the new term to the required nodes. The nid and vid values were the same on each node, and the value of my taxonomy term would need to be 84.

View file

@ -23,39 +23,39 @@ When I compare this to the previous gallery, I can see several differences whic
To do this, I'd need to query my website's database. To begin with, I wanted to have a list of all the galleries on my site which are published, and what they're unique node ID values are. To do this, I opened Sequel Pro and entered the following code: To do this, I'd need to query my website's database. To begin with, I wanted to have a list of all the galleries on my site which are published, and what they're unique node ID values are. To do this, I opened Sequel Pro and entered the following code:
~~~sql ```language-sql
SELECT title SELECT title
AS title, nid AS title, nid
AS gallery_idFROM node AS gallery_idFROM node
WHERE type = 'gallery' WHERE type = 'gallery'
AND status = 1; AND status = 1;
~~~ ```
As the nid value of each gallery corresponds with the 'field_gallery_nid' field within the content_type_photo field, I can now query the database and retrieve information about each specific gallery. As the nid value of each gallery corresponds with the 'field_gallery_nid' field within the content_type_photo field, I can now query the database and retrieve information about each specific gallery.
For example, using [aliasing](http://www.w3schools.com/sql/sql_alias.asp) within my SQL statement, I can retrieve a list of all the published photos within the 'British Squad 2008' gallery by using the following code: For example, using [aliasing](http://www.w3schools.com/sql/sql_alias.asp) within my SQL statement, I can retrieve a list of all the published photos within the 'British Squad 2008' gallery by using the following code:
~~~sql ```language-sql
SELECT n.title, n.nid, p.field_gallery_nid SELECT n.title, n.nid, p.field_gallery_nid
FROM node n, content_type_photo p FROM node n, content_type_photo p
WHERE p.field_gallery_nid = 105 WHERE p.field_gallery_nid = 105
AND n.status = 1 AND n.status = 1
AND n.nid = p.nid; AND n.nid = p.nid;
~~~ ```
I can easily change this to count the number of published nodes by changing the first line of the query to read SELECT COUNT(*). I can easily change this to count the number of published nodes by changing the first line of the query to read SELECT COUNT(*).
~~~sql ```language-sql
SELECT COUNT(*) SELECT COUNT(*)
FROM node n, content_type_photo p FROM node n, content_type_photo p
WHERE p.field_gallery_nid = 105 WHERE p.field_gallery_nid = 105
AND n.status = 1 AND n.status = 1
AND n.nid = p.nid; AND n.nid = p.nid;
~~~ ```
As I've used the [Views Attach](http://drupal.org/project/views_attach) module, and I'm embedding the photos directly into the Gallery nodes, I easily add this to each gallery by creating a custom node-gallery.tpl.php file within my theme. I can then use the following PHP code to retrieve the node ID for that specific gallery: As I've used the [Views Attach](http://drupal.org/project/views_attach) module, and I'm embedding the photos directly into the Gallery nodes, I easily add this to each gallery by creating a custom node-gallery.tpl.php file within my theme. I can then use the following PHP code to retrieve the node ID for that specific gallery:
~~~php ```language-php
<?php <?php
$selected_gallery = db_result(db_query(" $selected_gallery = db_result(db_query("
SELECT nid SELECT nid
@ -64,11 +64,11 @@ WHERE type = 'gallery'
AND title = '$title' AND title = '$title'
")); "));
?> ?>
~~~ ```
I can then use this variable as part of my next query to count the number of photos within that gallery, similar to what I did earlier. I can then use this variable as part of my next query to count the number of photos within that gallery, similar to what I did earlier.
~~~php ```language-php
<?php <?php
$gallery_total = db_result(db_query(" $gallery_total = db_result(db_query("
SELECT COUNT(*) SELECT COUNT(*)
@ -76,11 +76,11 @@ FROM {content_type_photo}
WHERE field_gallery_nid = $selected_gallery WHERE field_gallery_nid = $selected_gallery
")); "));
?> ?>
~~~ ```
Next, I wanted to display the date that the last photo was displayed within each album. This was done by using a similar query that also sorted the results in a descending order, and limited it to one result - effectively only returning the created date for the newest photo. Next, I wanted to display the date that the last photo was displayed within each album. This was done by using a similar query that also sorted the results in a descending order, and limited it to one result - effectively only returning the created date for the newest photo.
~~~php ```language-php
<?php <?php
$latest_photo = db_result(db_query(" $latest_photo = db_result(db_query("
SELECT n.created SELECT n.created
@ -90,11 +90,11 @@ AND n.nid = p.nid
ORDER BY n.created DESC LIMIT 1 ORDER BY n.created DESC LIMIT 1
")); "));
?> ?>
~~~ ```
This was all then added into a 'print' statement which displayed it into the page. This was all then added into a 'print' statement which displayed it into the page.
~~~php ```language-php
<?php <?php
if ($selected_gallery_total != 0) { if ($selected_gallery_total != 0) {
$output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.'; $output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.';
@ -102,13 +102,13 @@ if ($selected_gallery_total != 0) {
print $output; print $output;
} }
?> ?>
~~~ ```
OK, so let's take a look at the Gallery so far: OK, so let's take a look at the Gallery so far:
You will notice that the returned date value for the latest photo added is displaying the UNIX timestamp instead of in a more readable format. This can be changed by altering the 'print' statement to include a PHP 'date' function: You will notice that the returned date value for the latest photo added is displaying the UNIX timestamp instead of in a more readable format. This can be changed by altering the 'print' statement to include a PHP 'date' function:
~~~php ```language-php
<?php <?php
if ($selected_gallery_total != 0) { if ($selected_gallery_total != 0) {
$output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.'; $output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.';
@ -116,7 +116,7 @@ if ($selected_gallery_total != 0) {
print $output; print $output;
} }
?> ?>
~~~ ```
The values that I've entered are from [this page](http://php.net/manual/en/function.date.php) on PHP.net, and can be changed according on how you want the date to be displayed. The values that I've entered are from [this page](http://php.net/manual/en/function.date.php) on PHP.net, and can be changed according on how you want the date to be displayed.

View file

@ -13,18 +13,18 @@ At the end of my last post, I'd finished creating the first part of the new pho
Firstly, I'll refer to the previous list of published galleries that I created before, and create something different that also displays the created and modified dates. Picking the node ID of the required gallery, I used the following SQL query to display a list of photos. Firstly, I'll refer to the previous list of published galleries that I created before, and create something different that also displays the created and modified dates. Picking the node ID of the required gallery, I used the following SQL query to display a list of photos.
~~~sql ```language-sql
SELECT n.title, n.nid, n.created, n.changed, p.field_gallery_nid SELECT n.title, n.nid, n.created, n.changed, p.field_gallery_nid
FROM node n, content_type_photo pWHERE n.type = 'photo' FROM node n, content_type_photo pWHERE n.type = 'photo'
AND p.field_gallery_nid = 103AND n.nid = p.nid AND p.field_gallery_nid = 103AND n.nid = p.nid
ORDER BY n.nid ASC; ORDER BY n.nid ASC;
~~~ ```
When I look back at the old photo gallery, I can see that the previous 'last added' date was June 27, 2008. So, how do I update my new photos to reflect that date? Using <http://www.onlineconversion.com/unix_time.htm>, I can enter the required date in its readable format, and it will give me the equivilent UNIX timestamp. To keep things relatively simple, I'll set all photos within this gallery to the same time. When I look back at the old photo gallery, I can see that the previous 'last added' date was June 27, 2008. So, how do I update my new photos to reflect that date? Using <http://www.onlineconversion.com/unix_time.htm>, I can enter the required date in its readable format, and it will give me the equivilent UNIX timestamp. To keep things relatively simple, I'll set all photos within this gallery to the same time.
The result that I'm given is '1217149200'. I can now use an UPDATE statement within another SQL query to update the created and modified dates. The result that I'm given is '1217149200'. I can now use an UPDATE statement within another SQL query to update the created and modified dates.
~~~sql ```language-sql
UPDATE node UPDATE node
INNER JOIN content_type_photo INNER JOIN content_type_photo
ON node.nid = content_type_photo.nid ON node.nid = content_type_photo.nid
@ -32,7 +32,7 @@ SET
node.created = 1217149200, node.created = 1217149200,
node.changed = 1217149200 node.changed = 1217149200
WHERE content_type_photo.field_gallery_nid = 103 WHERE content_type_photo.field_gallery_nid = 103
~~~ ```
Now when I query the database, both the created and modified databases have been updated, and when I return to the new photo gallery, the updated value is being displayed. Now when I query the database, both the created and modified databases have been updated, and when I return to the new photo gallery, the updated value is being displayed.

View file

@ -15,17 +15,23 @@ Earlier this year, I posted a solution to [an issue](http://drupal.org/node/7538
{% block content %} {% block content %}
To begin with, a download a fresh copy of Drupal 6.19 and created a copy of the original user.pages.inc file. Within the duplicate file, I made the same changes to the function that I did in earlier code, and saved the changes. Now, within my Terminal, I can navigate to Drupal's root directory and create the patch. To begin with, a download a fresh copy of Drupal 6.19 and created a copy of the original user.pages.inc file. Within the duplicate file, I made the same changes to the function that I did in earlier code, and saved the changes. Now, within my Terminal, I can navigate to Drupal's root directory and create the patch.
diff -rup modules/user/user.pages.inc modules/user/user.pages2.inc > /Users/oliver/Desktop/different_messages_for_blocked_users.patch ```language-bash
diff -rup modules/user/user.pages.inc modules/user/user.pages2.inc > /Users/oliver/Desktop/different_messages_for_blocked_users.patch
```
This command compares the differences between the two files, and creates the specified patch file. This command compares the differences between the two files, and creates the specified patch file.
To apply the patch to my Drupal installation, I go back to Terminal and run the following code: To apply the patch to my Drupal installation, I go back to Terminal and run the following code:
patch -p0 < /Users/oliver/Desktop/different_messages_for_blocked_users.patch ```language-bash
patch -p0 < /Users/oliver/Desktop/different_messages_for_blocked_users.patch
```
If, for some reason, I need to reverse the patch, I can run this code: If, for some reason, I need to reverse the patch, I can run this code:
patch -p0 -R < /Users/oliver/Desktop/different_messages_for_blocked_users.patch ```language-bash
patch -p0 -R < /Users/oliver/Desktop/different_messages_for_blocked_users.patch
```
And that's it! And that's it!

View file

@ -11,19 +11,19 @@ I've called it 'Taxonomy', and it's similar to the original 'All Galleries' view
Within that file, I can remove the standard content output. This still outputs the heading information from the original View. I can now use the function called 'views_embed_view' to embed my taxonomy display onto the display. The views_embed_view function is as follows: Within that file, I can remove the standard content output. This still outputs the heading information from the original View. I can now use the function called 'views_embed_view' to embed my taxonomy display onto the display. The views_embed_view function is as follows:
~~~php ```language-php
<?php views_embed_view('my_view', 'block_1', $arg1, $arg2); ?> <?php views_embed_view('my_view', 'block_1', $arg1, $arg2); ?>
~~~ ```
So, to display the galleries that are assigned the taxonomy of 'tournaments', I can use the following: So, to display the galleries that are assigned the taxonomy of 'tournaments', I can use the following:
~~~php ```language-php
<?php print views_embed_view('photo_gallery', 'page_2', 'tournaments'); ?> <?php print views_embed_view('photo_gallery', 'page_2', 'tournaments'); ?>
~~~ ```
To reduce the amount of code needed, I can use the following 'while' loop to generate the same code for each taxonomy term. It dynamically retrieves the relevant taxonomy terms from the database, and uses each name as the argument for the view. To reduce the amount of code needed, I can use the following 'while' loop to generate the same code for each taxonomy term. It dynamically retrieves the relevant taxonomy terms from the database, and uses each name as the argument for the view.
~~~php ```language-php
<?php <?php
$terms = db_query("SELECT * FROM {term_data} WHERE vid = 1"); $terms = db_query("SELECT * FROM {term_data} WHERE vid = 1");
while ($term = db_fetch_array($terms)) { while ($term = db_fetch_array($terms)) {
@ -31,4 +31,4 @@ while ($term = db_fetch_array($terms)) {
print views_embed_view('gallery', 'page_2', $term['name']); print views_embed_view('gallery', 'page_2', $term['name']);
} }
?> ?>
~~~ ```

View file

@ -7,7 +7,7 @@ use: [posts]
--- ---
Today, I realised that I hadn't published the code that I used to create the total figures of galleries and photos at the top of the gallery (I said at the end of [Part 2](/blog/create-better-photo-gallery-drupal-part-2/ "Create a Better Photo Gallery in Drupal - Part 2") that I'd include it in [Part 3](/blog/create-better-photo-gallery-drupal-part-3/ "Create a Better Photo Gallery in Drupal - Part 3"), but I forgot). So, here it is: Today, I realised that I hadn't published the code that I used to create the total figures of galleries and photos at the top of the gallery (I said at the end of [Part 2](/blog/create-better-photo-gallery-drupal-part-2/ "Create a Better Photo Gallery in Drupal - Part 2") that I'd include it in [Part 3](/blog/create-better-photo-gallery-drupal-part-3/ "Create a Better Photo Gallery in Drupal - Part 3"), but I forgot). So, here it is:
~~~php ```language-php
<?php <?php
// Queries the database and returns a list of nids of published galleries. // Queries the database and returns a list of nids of published galleries.
@ -51,6 +51,6 @@ else {
} }
print '.'; print '.';
?> ?>
~~~ ```
It was applied to the view as a header which had the input format set to PHP code. It was applied to the view as a header which had the input format set to PHP code.

View file

@ -12,17 +12,17 @@ use: [posts]
--- ---
As in [the original post](/blog/add-taxonomy-term-multiple-nodes-using-sql/ "Quickly adding a taxonomy term to multiple nodes using SQL"), I'd generated a list of node ID values, and needed to add structure the SQL update statment formatted in a certain way. However, I changed my inital query slightly to out put the same nid value twice. As in [the original post](/blog/add-taxonomy-term-multiple-nodes-using-sql/ "Quickly adding a taxonomy term to multiple nodes using SQL"), I'd generated a list of node ID values, and needed to add structure the SQL update statment formatted in a certain way. However, I changed my inital query slightly to out put the same nid value twice.
~~~sql ```language-sql
SELECT nid, nid FROM node WHERE TYPE = 'blog' ORDER BY nid ASC; SELECT nid, nid FROM node WHERE TYPE = 'blog' ORDER BY nid ASC;
~~~ ```
Then, I could select all of the returned rows, copy the values, and paste them into Coda: Then, I could select all of the returned rows, copy the values, and paste them into Coda:
As before, I needed my SQL update statement to be in the following format: As before, I needed my SQL update statement to be in the following format:
~~~sql ```language-sql
INSERT INTO term_node VALUE (nid, vid, tid), (nid2, vid2, tid); INSERT INTO term_node VALUE (nid, vid, tid), (nid2, vid2, tid);
~~~ ```
As I mentioned previously, the nid and vid values are the same for each node, and the tid will remain constant. In this case, the tid value that I needed to use was '63'. As I mentioned previously, the nid and vid values are the same for each node, and the tid will remain constant. In this case, the tid value that I needed to use was '63'.

View file

@ -12,11 +12,11 @@ For example, mine is <https://www.facebook.com/pages/edit/?id=143394365692197&am
I've also wrapped the output in a number_format() function so that it properly formatted with commas etc - like where I've used it within the [Gold Event listing](http://www.horseandcountry.tv/events/paid) on the Horse & Country TV website. I've also wrapped the output in a number_format() function so that it properly formatted with commas etc - like where I've used it within the [Gold Event listing](http://www.horseandcountry.tv/events/paid) on the Horse & Country TV website.
~~~php ```language-php
$page_id = "143394365692197"; $page_id = "143394365692197";
$xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&amp;query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot"); $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&amp;query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
$fans = $xml->page->fan_count; $fans = $xml->page->fan_count;
print number_format($fans); print number_format($fans);
~~~ ```
This code was originally found at <http://wp-snippets.com/display-number-facebook-fans>. This code was originally found at <http://wp-snippets.com/display-number-facebook-fans>.

View file

@ -13,11 +13,15 @@ Note: As I was using Ubuntu, I was using the 'apt-get' command to download and i
Firstly, I'm going to ensure that all of my installed packages are up to date, and install any available updates. Firstly, I'm going to ensure that all of my installed packages are up to date, and install any available updates.
$ sudo apt-get update ```language-bash
$ sudo apt-get update
```
Now, I need to download the subversion, subversion-tools and libapache2 packages. Now, I need to download the subversion, subversion-tools and libapache2 packages.
$ sudo apt-get install subversion subversion-tools libapache2-svn ```language-bash
$ sudo apt-get install subversion subversion-tools libapache2-svn
```
These are all of the packages that are needed to run a Subversion server. These are all of the packages that are needed to run a Subversion server.
@ -25,55 +29,71 @@ These are all of the packages that are needed to run a Subversion server.
Now, I need to create the directory where my repositories are going to sit. I've chosen this directory as I know that it's one that is accessible to my managed backup service. Now, I need to create the directory where my repositories are going to sit. I've chosen this directory as I know that it's one that is accessible to my managed backup service.
$ sudo mkdir /home/svn ```language-bash
$ sudo mkdir /home/svn
```
## Create a test repository ## Create a test repository
First, I'll create a new folder in which I'll create my test project, and then I'll create a repository for it. First, I'll create a new folder in which I'll create my test project, and then I'll create a repository for it.
$ sudo mkdir ~/test ```language-bash
$ sudo svnadmin create /home/svn/test -m 'initial project structure' $ sudo mkdir ~/test
$ sudo svnadmin create /home/svn/test -m 'initial project structure'
```
This will create a new repository containing the base file structure. This will create a new repository containing the base file structure.
## Adding files into the test project ## Adding files into the test project
$ cd ~/test ```language-bash
$ mkdir trunk tags branches $ cd ~/test
$ mkdir trunk tags branches
```
I can now import these new directories into the test repository. I can now import these new directories into the test repository.
$ sudo svn import ~/test file:///home/svn/test -m 'Initial project directories' ```language-bash
$ sudo svn import ~/test file:///home/svn/test -m 'Initial project directories'
```
This both adds and commits these new directories into the repository. This both adds and commits these new directories into the repository.
In order for Apache to access the SVN repositories, the `/home/svn` directory needs to be owned by the same user and group that Apache runs as. In Ubuntu, this is usually www-data. To change the owner of a directory, use the chown command. In order for Apache to access the SVN repositories, the `/home/svn` directory needs to be owned by the same user and group that Apache runs as. In Ubuntu, this is usually www-data. To change the owner of a directory, use the chown command.
$ sudo chown -R www-data:www-data /home/svn ```language-bash
$ sudo chown -R www-data:www-data /home/svn
```
## Configuring Apache ## Configuring Apache
The first thing that I need to do is enable the dav_svn Apache module, using the a2enmod command. The first thing that I need to do is enable the dav_svn Apache module, using the a2enmod command.
$ sudo a2enmod dav_svn ```language-bash
$ sudo a2enmod dav_svn
```
With this enabled, now I need to modify the Apache configuration file. With this enabled, now I need to modify the Apache configuration file.
$ cd /etc/apache2 ```language-bash
$ sudo nano apache2.conf $ cd /etc/apache2
$ sudo nano apache2.conf
```
At the bottom of the file, add the following lines, and then save the file by pressing Ctrl+X. At the bottom of the file, add the following lines, and then save the file by pressing Ctrl+X.
~~~ ```language-apacheconf
<Location "/svn"> <Location "/svn">
DAV svn DAV svn
SVNParentPath /home/svn SVNParentPath /home/svn
</Location> </Location>
~~~ ```
With this saved, restart the Apache service for the changes to be applied. With this saved, restart the Apache service for the changes to be applied.
sudo service apache2 restart ```language-bash
sudo service apache2 restart
```
I can now browse through my test repository by opening Firefox, and navigating to `http://127.0.0.1/svn/test`. Here, I can now see my three directories, although they are currently all empty. I can now browse through my test repository by opening Firefox, and navigating to `http://127.0.0.1/svn/test`. Here, I can now see my three directories, although they are currently all empty.
@ -85,7 +105,7 @@ Before I start committing any files to the test repository, I want to ensure tha
Re-open apache2.conf, and replace the SVN Location information with this: Re-open apache2.conf, and replace the SVN Location information with this:
~~~~ ```language-apacheconf
<Location "/svn"> <Location "/svn">
DAV svn DAV svn
SVNParentPath /home/svn SVNParentPath /home/svn
@ -94,11 +114,13 @@ Re-open apache2.conf, and replace the SVN Location information with this:
AuthUserFile /etc/svn-auth AuthUserFile /etc/svn-auth
Require valid-user Require valid-user
</Location> </Location>
~~~~ ```
Now I need to create the password file. Now I need to create the password file.
$ htpasswd -cm /etc/svn-auth oliver ```language-bash
$ htpasswd -cm /etc/svn-auth oliver
```
I'm prompted to enter and confirm my password, and then my details are saved. The Apache service will need to be restarted again, and then the user will need to authenticate themselves before viewing the repositories. I'm prompted to enter and confirm my password, and then my details are saved. The Apache service will need to be restarted again, and then the user will need to authenticate themselves before viewing the repositories.
@ -108,15 +130,19 @@ I'm prompted to enter and confirm my password, and then my details are saved. Th
For example, now want to checkout the files within my repository into a new directory called 'test2' within my home directory. Firstly, I need to create the new directory, and then I can issue the checkout command. For example, now want to checkout the files within my repository into a new directory called 'test2' within my home directory. Firstly, I need to create the new directory, and then I can issue the checkout command.
$ cd ~ ```language-bash
$ mkdir test2 $ cd ~
$ svn checkout http://127.0.0.1/svn/test/trunk test2 $ mkdir test2
$ svn checkout http://127.0.0.1/svn/test/trunk test2
```
I'm passing the command two arguments - the first is the URL of the repository's trunk directory, and the second is the directory where the files are to be placed. As no files have been commited yet into the trunk, it appears to be empty - but if you perform an ls -la command, you'll see that there is a hidden .svn directory. I'm passing the command two arguments - the first is the URL of the repository's trunk directory, and the second is the directory where the files are to be placed. As no files have been commited yet into the trunk, it appears to be empty - but if you perform an ls -la command, you'll see that there is a hidden .svn directory.
Now you can start adding files into the directory. Once you've created your files, perform a svn add command, passing in individual filenames as further arguments. Now you can start adding files into the directory. Once you've created your files, perform a svn add command, passing in individual filenames as further arguments.
$ svn add index.php ```language-bash
$ svn add * $ svn add index.php
$ svn add *
```
With all the required files added, they can be committed using `svn commit -m 'commit message'` command, and the server can be updated using the svn up command. With all the required files added, they can be committed using `svn commit -m 'commit message'` command, and the server can be updated using the svn up command.

View file

@ -14,20 +14,28 @@ In this tutorial I'll be showing how to create an [Omega](http://drupal.org/proj
The first thing that I need to do is download the Omega theme and the Omega Tools and [LESS](http://drupal.org/project/less "LESS module on drupal.org") modules, and then to enable both modules. I'm doing this using Drush, but you can of course do this via the admin interface at admin/modules. The first thing that I need to do is download the Omega theme and the Omega Tools and [LESS](http://drupal.org/project/less "LESS module on drupal.org") modules, and then to enable both modules. I'm doing this using Drush, but you can of course do this via the admin interface at admin/modules.
$ drush dl less omega omega_tools; ```language-bash
$ drush en -y less omega_tools $ drush dl less omega omega_tools;
$ drush en -y less omega_tools
```
With the Omega Tools module enabled I get the drush omega-subtheme command that creates my Omega subtheme programatically. Using this command, I'm creating a new subtheme, enabling it and setting it as the default theme on my site. With the Omega Tools module enabled I get the drush omega-subtheme command that creates my Omega subtheme programatically. Using this command, I'm creating a new subtheme, enabling it and setting it as the default theme on my site.
$ drush omega-subtheme "Oliver Davies" --machine_name="oliverdavies" --enable --set-default ```language-bash
$ drush omega-subtheme "Oliver Davies" --machine_name="oliverdavies" --enable --set-default
```
By default, four stylesheets are created within the subtheme's css directory. The first thing that I'm going to do is rename `global.css` to `global.less`. By default, four stylesheets are created within the subtheme's css directory. The first thing that I'm going to do is rename `global.css` to `global.less`.
$ mv css/global.css css/global.less ```language-bash
$ mv css/global.css css/global.less
```
Now I need to find all references to global.css within my oliverdavies.info file. I did this using `$ nano oliverdavies.info`, pressing `Ctrl+W` to search, then `Ctrl+R` to replace, entering `global.css` as the search phrase, and then `global.less` as the replacement text. After making any changes to oliverdavies.info, I need to clear Drupal's caches for the changes to be applied. Now I need to find all references to global.css within my oliverdavies.info file. I did this using `$ nano oliverdavies.info`, pressing `Ctrl+W` to search, then `Ctrl+R` to replace, entering `global.css` as the search phrase, and then `global.less` as the replacement text. After making any changes to oliverdavies.info, I need to clear Drupal's caches for the changes to be applied.
$ drush cc all ```language-bash
$ drush cc all
```
I tested my changes by making some quick additions to my global.less file and reloading the page. I tested my changes by making some quick additions to my global.less file and reloading the page.

View file

@ -19,31 +19,31 @@ Today, I had a situation where I was displaying a list of teasers for news artic
I have previously seen it done this way by adding this into in a node.tpl.php file: I have previously seen it done this way by adding this into in a node.tpl.php file:
~~~~ ```language-php
if ($teaser) { if ($teaser) {
// The teaser output. // The teaser output.
} }
else { else {
// The whole node output. // The whole node output.
} }
~~~~ ```
However, I decided to do something different and create a separate template file just for teasers. This is done using the hook_preprocess_HOOK function that I can add into my theme's template.php file. However, I decided to do something different and create a separate template file just for teasers. This is done using the hook_preprocess_HOOK function that I can add into my theme's template.php file.
The function requires the node variables as an argument - one of which is theme_hook_suggestions. This is an array of suggested template files that Drupal looks for and attempts to use when displaying a node, and this is where I'll be adding a new suggestion for my teaser-specific template. Using the `debug()` function, I can easily see what's already there. The function requires the node variables as an argument - one of which is theme_hook_suggestions. This is an array of suggested template files that Drupal looks for and attempts to use when displaying a node, and this is where I'll be adding a new suggestion for my teaser-specific template. Using the `debug()` function, I can easily see what's already there.
~~~~php ```language-php
array ( array (
0 => 'node__article', 0 => 'node__article',
1 => 'node__343', 1 => 'node__343',
2 => 'node__view__latest_news', 2 => 'node__view__latest_news',
3 => 'node__view__latest_news__page', 3 => 'node__view__latest_news__page',
) )
~~~~ ```
So, within my theme's template.php file: So, within my theme's template.php file:
~~~~php ```language-php
/** /**
* Implementation of hook_preprocess_HOOK(). * Implementation of hook_preprocess_HOOK().
*/ */
@ -55,11 +55,11 @@ function mytheme_preprocess_node(&$variables) {
$variables['theme_hook_suggestions'][] = 'node__' . $node->type . '_teaser'; $variables['theme_hook_suggestions'][] = 'node__' . $node->type . '_teaser';
} }
} }
~~~~ ```
After adding the new suggestion: After adding the new suggestion:
~~~~php ```language-php
array ( array (
0 => 'node__article', 0 => 'node__article',
1 => 'node__343', 1 => 'node__343',
@ -67,7 +67,7 @@ array (
3 => 'node__view__latest_news__page', 3 => 'node__view__latest_news__page',
4 => 'node__article_teaser', 4 => 'node__article_teaser',
) )
~~~~ ```
Now, within my theme I can create a new node--article-teaser.tpl.php template file and this will get called instead of the node--article.tpl.php when a teaser is loaded. As I'm not specifying the node type specifically and using the dynamic <em>$node->type</em> value within my suggestion, this will also apply for all other content types on my site and not just news articles. Now, within my theme I can create a new node--article-teaser.tpl.php template file and this will get called instead of the node--article.tpl.php when a teaser is loaded. As I'm not specifying the node type specifically and using the dynamic <em>$node->type</em> value within my suggestion, this will also apply for all other content types on my site and not just news articles.
{% endblock %} {% endblock %}

View file

@ -14,14 +14,16 @@ Rather than delete these files or change the file permissions manually for each
{% endblock %} {% endblock %}
{% block content %} {% block content %}
When you download [Drupal](http://drupal.org/project/drupal), there are several text files that are placed in the root of your installation. You don't want or need these to be visible to anyone attempting to view them in a browser - especially CHANGELOG.txt as that includes the exact version of Drupal you are running and could therefore have security implications. When you download [Drupal](http://drupal.org/project/drupal), there are several text files that are placed in the root of your installation. You don't want or need these to be visible to anyone attempting to view them in a browser - especially `CHANGELOG.txt` as that includes the exact version of Drupal you are running and could therefore have security implications.
Rather than delete these files or change the file permissions manually for each file, I can add the following lines into my VirtualHost configuration: Rather than delete these files or change the file permissions manually for each file, I can add the following lines into my VirtualHost configuration:
<Files ~ "\.txt$"> ```language-apacheconf
<Files ~ "\.txt$">
Order deny,allow Order deny,allow
Deny from all Deny from all
</Files> </Files>
```
This prevents any files with a .txt extension from being accessed and rendered in a web browser. This prevents any files with a .txt extension from being accessed and rendered in a web browser.
{% endblock %} {% endblock %}

View file

@ -13,9 +13,14 @@ How to checkout a specific revision from a SVN (Subversion) repository.
{% block content %} {% block content %}
If you're checking out the repository for the first time: If you're checking out the repository for the first time:
svn checkout -r 1234 url://repository/path ```language-bash
$ svn checkout -r 1234 url://repository/path
```
If you already have the repository checked out: If you already have the repository checked out:
svn up -r 1234 ```language-bash
$ svn up -r 1234
```
{% endblock %} {% endblock %}

View file

@ -18,11 +18,13 @@ How to use a date popup calendar within your custom module.
{% block content %} {% block content %}
First, I need to download the [Date](http://drupal.org/project/date "Date module on Drupal.org") module, and make my module dependent on date_popup by adding the following line into my module's .info file. First, I need to download the [Date](http://drupal.org/project/date "Date module on Drupal.org") module, and make my module dependent on date_popup by adding the following line into my module's .info file.
dependencies[] = date_popup ```language-ini
dependencies[] = date_popup
```
Within my form builder function: Within my form builder function:
~~~php ```language-php
$form['date'] = array( $form['date'] = array(
'#title' => t('Arrival date'), '#title' => t('Arrival date'),
@ -38,5 +40,5 @@ $form['date'] = array(
// Default value must be in 'Y-m-d' format. // Default value must be in 'Y-m-d' format.
'#default_value' => date('Y-m-d', time()), '#default_value' => date('Y-m-d', time()),
); );
~~~ ```
{% endblock %} {% endblock %}

View file

@ -16,16 +16,20 @@ How to use the .htaccess file to forward to a different domain.
{% block content %} {% block content %}
Within the mod_rewrite section of your .htaccess file, add the following lines: Within the mod_rewrite section of your .htaccess file, add the following lines:
RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$ ```language-apacheconf
RewriteRule (.*) http://yoursite.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
```
This automatically forwards any users from http://yoursite.co.uk to http://yoursite.com. This can also be used to forward multiple domains: This automatically forwards any users from http://yoursite.co.uk to http://yoursite.com. This can also be used to forward multiple domains:
RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$ [OR] ```language-apacheconf
RewriteCond %{HTTP_HOST} ^yoursite\.info$ [OR] RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^yoursite\.biz$ [OR] RewriteCond %{HTTP_HOST} ^yoursite\.info$ [OR]
RewriteCond %{HTTP_HOST} ^yoursite\.eu$ RewriteCond %{HTTP_HOST} ^yoursite\.biz$ [OR]
RewriteRule (.*) http://yoursite.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^yoursite\.eu$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
```
If any of the RewriteCond conditions apply, then the RewriteRule is executed. If any of the RewriteCond conditions apply, then the RewriteRule is executed.
{% endblock %} {% endblock %}

View file

@ -13,7 +13,7 @@ An example .info file for a Drupal 7 theme.
{% endblock %} {% endblock %}
{% block content %} {% block content %}
~~~ ```language-ini
name = My Theme name = My Theme
description = A description of my theme description = A description of my theme
core = 7.x core = 7.x
@ -41,5 +41,5 @@ stylesheets[print][] = css/print.css
# Add javascript files # Add javascript files
styles[] = js/mytheme.js styles[] = js/mytheme.js
~~~ ```
{% endblock %} {% endblock %}

View file

@ -20,7 +20,7 @@ If you use a lot of process and preprocess functions within your Drupal theme, t
The first step is to use the default mytheme_process() and mytheme_preprocess() functions to utilise my custom function. So within my template.php file: The first step is to use the default mytheme_process() and mytheme_preprocess() functions to utilise my custom function. So within my template.php file:
~~~php ```language-php
<?php <?php
/** /**
@ -40,11 +40,11 @@ function mytheme_preprocess(&$variables, $hook) {
function mytheme_process(&$variables, $hook) { function mytheme_process(&$variables, $hook) {
mytheme_invoke('process', $hook, $variables); mytheme_invoke('process', $hook, $variables);
} }
~~~ ```
Now, to write the `mytheme_invoke()` function: Now, to write the `mytheme_invoke()` function:
~~~php ```language-php
<?php <?php
/** /**
@ -85,7 +85,7 @@ function mytheme_invoke($type, $hook, &$variables) {
$function($variables); $function($variables);
} }
} }
~~~ ```
As `mytheme_invoke()` checks to see if the function already exists before searching for checking the include files, I could still add the functions into template.php as normal and this would override any corresponding include file. As `mytheme_invoke()` checks to see if the function already exists before searching for checking the include files, I could still add the functions into template.php as normal and this would override any corresponding include file.
{% endblock %} {% endblock %}

View file

@ -23,13 +23,13 @@ This week I released the first version of the Nomensa Accessible Media Player mo
The library can be downloaded directly from GitHub, and should be placed within you *sites/all/libraries/nomensa_amp* directory. The library can be downloaded directly from GitHub, and should be placed within you *sites/all/libraries/nomensa_amp* directory.
~~~~ ```language-bash
drush dl libraries nomensa_amp drush dl libraries nomensa_amp
git clone https://github.com/nomensa/Accessible-Media-Player sites/all/libraries/nomensa_amp git clone https://github.com/nomensa/Accessible-Media-Player sites/all/libraries/nomensa_amp
cd sites/all/libraries/nomensa_amp cd sites/all/libraries/nomensa_amp
rm -rf Accessible-media-player_2.0_documentation.pdf example/ README.md rm -rf Accessible-media-player_2.0_documentation.pdf example/ README.md
drush en -y nomensa_amp drush en -y nomensa_amp
~~~~ ```
### Configure the Module ### Configure the Module
@ -41,11 +41,15 @@ Within your content add links to your videos. For example:
### YouTube ### YouTube
<a href="http://www.youtube.com/watch?v=Zi31YMGmQC4">Checking colour contrast</a> ```language-html
<a href="http://www.youtube.com/watch?v=Zi31YMGmQC4">Checking colour contrast</a>
```
### Vimeo ### Vimeo
<a href="http://vimeo.com/33729937">Screen readers are strange, when you're a stranger by Leonie Watson</a> ```language-html
<a href="http://vimeo.com/33729937">Screen readers are strange, when you're a stranger by Leonie Watson</a>
```
## Adding captions ## Adding captions
@ -57,7 +61,9 @@ The best way that I can suggest to do this is to use a File field to upload your
For example: For example:
<a href="http://www.youtube.com/watch?v=Zi31YMGmQC4">Checking colour contrast</a> <a class="captions" href="http://oliverdavies.co.uk/sites/default/files/checking-colour-contrast-captions.xml">Captions for Checking Colour Contrast</a> ```language-html
<a href="http://www.youtube.com/watch?v=Zi31YMGmQC4">Checking colour contrast</a> <a class="captions" href="http://oliverdavies.co.uk/sites/default/files/checking-colour-contrast-captions.xml">Captions for Checking Colour Contrast</a>
```
## Screencast ## Screencast

View file

@ -17,7 +17,7 @@ For reference, this is the code needed to display a menu in a Drupal 7 template
{% block content %} {% block content %}
For reference, this is the code needed to display a menu in a Drupal 7 template file, including the navigation ARIA role. For reference, this is the code needed to display a menu in a Drupal 7 template file, including the navigation ARIA role.
~~~php ```language-php
$menu_name = 'menu-footer-menu'; $menu_name = 'menu-footer-menu';
$menu_id = 'footer-menu'; $menu_id = 'footer-menu';
print theme('links', array( print theme('links', array(
@ -28,5 +28,5 @@ print theme('links', array(
'class'=> array('links', 'inline') 'class'=> array('links', 'inline')
) )
)); ));
~~~ ```
{% endblock %} {% endblock %}

View file

@ -18,7 +18,7 @@ These preferences ensure that the code is compliant with [Drupal coding standard
These can be changed by going to Preferences > Settings - User. These can be changed by going to Preferences > Settings - User.
~~~ ```language-json
{ {
"color_scheme": "Packages/Theme - Aqua/Color Schemes/Tomorrow Night Aqua.tmTheme", "color_scheme": "Packages/Theme - Aqua/Color Schemes/Tomorrow Night Aqua.tmTheme",
"default_line_ending": "unix", "default_line_ending": "unix",
@ -79,18 +79,18 @@ These can be changed by going to Preferences > Settings - User.
"trim_trailing_white_space_on_save": true, "trim_trailing_white_space_on_save": true,
"word_wrap": false "word_wrap": false
} }
~~~ ```
## Key bindings ## Key bindings
These can be changed by going to Preferences > Key Bindings - User. These can be changed by going to Preferences > Key Bindings - User.
~~~ ```language-json
[ [
{ "keys": ["alt+s"], "command": "toggle_side_bar" }, { "keys": ["alt+s"], "command": "toggle_side_bar" },
{ "keys": ["alt+r"], "command": "reindent" } { "keys": ["alt+r"], "command": "reindent" }
] ]
~~~ ```
## Packages ## Packages

View file

@ -14,7 +14,9 @@ How to open Sublime Text from the command line.
{% block content %} {% block content %}
Paste the following code into the Mac OS X Terminal, assuming that you've installed Sublime Text 2 into the /Applications folder. Paste the following code into the Mac OS X Terminal, assuming that you've installed Sublime Text 2 into the /Applications folder.
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/sublime ```language-bash
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/sublime
```
Now you can type `sublime <filename>` open a file or directory in Sublime Text, or `sublime .` to open the current directory. Now you can type `sublime <filename>` open a file or directory in Sublime Text, or `sublime .` to open the current directory.

View file

@ -29,17 +29,21 @@ Alternatively, you could use a base theme like [Sasson](http://drupal.org/projec
The first thing to do is download the PHPSass library from [GitHub](https://github.com/richthegeek/phpsass "PHPSass on GitHub"), as this is a requirement of the Sassy module and we can't enable it without the library. So, in a Terminal window: The first thing to do is download the PHPSass library from [GitHub](https://github.com/richthegeek/phpsass "PHPSass on GitHub"), as this is a requirement of the Sassy module and we can't enable it without the library. So, in a Terminal window:
$ mkdir -p sites/all/libraries; ```language-bash
$ cd sites/all/libraries; $ mkdir -p sites/all/libraries;
$ wget https://github.com/richthegeek/phpsass/archive/master.tar.gz; $ cd sites/all/libraries;
$ tar zxf master.tar.gz; $ wget https://github.com/richthegeek/phpsass/archive/master.tar.gz;
$ rm master.tar.gz; $ tar zxf master.tar.gz;
$ mv phpsass-master/ phpsass $ rm master.tar.gz;
$ mv phpsass-master/ phpsass
```
Or, if you're using Drush Make files: Or, if you're using Drush Make files:
libraries[phpsass][download][type] = "get" ```language-ini
libraries[phpsass][download][url] = "https://github.com/richthegeek/phpsass/archive/master.tar.gz" libraries[phpsass][download][type] = "get"
libraries[phpsass][download][url] = "https://github.com/richthegeek/phpsass/archive/master.tar.gz"
```
The PHPSass library should now be located at `sites/all/libraries/phpsass`. The PHPSass library should now be located at `sites/all/libraries/phpsass`.
@ -47,8 +51,10 @@ The PHPSass library should now be located at `sites/all/libraries/phpsass`.
This is easy if you use [Drush](http://drupal.org/project/drush): This is easy if you use [Drush](http://drupal.org/project/drush):
$ drush dl libraries prepro sassy ```language-bash
$ drush en -y libraries prepro sassy sassy_compass $ drush dl libraries prepro sassy
$ drush en -y libraries prepro sassy sassy_compass
```
Otherwise, download the each module from it's respective project page and place it within your `sites/all/modules` or `sites/all/modules/contrib` directory. Otherwise, download the each module from it's respective project page and place it within your `sites/all/modules` or `sites/all/modules/contrib` directory.

View file

@ -17,35 +17,35 @@ I see this regularly when working on Drupal sites when someone wants to check wh
{% block content %} {% block content %}
I see this regularly when working on Drupal sites when someone wants to check whether the current user is logged in to Drupal (authenticated) or not (anonymous): I see this regularly when working on Drupal sites when someone wants to check whether the current user is logged in to Drupal (authenticated) or not (anonymous):
~~~~ ```language-php
global $user; global $user;
if ($user->uid) { if ($user->uid) {
// The user is logged in. // The user is logged in.
} }
~~~~ ```
or or
~~~~ ```language-php
global $user; global $user;
if (!$user->uid) { if (!$user->uid) {
// The user is not logged in. // The user is not logged in.
} }
~~~~ ```
The better way to do this is to use the [user_is_logged_in()](http://api.drupal.org/api/drupal/modules!user!user.module/function/user_is_logged_in/7) function. The better way to do this is to use the [user_is_logged_in()](http://api.drupal.org/api/drupal/modules!user!user.module/function/user_is_logged_in/7) function.
~~~~ ```language-php
if (user_is_logged_in()) { if (user_is_logged_in()) {
// Do something. // Do something.
} }
~~~~ ```
This returns a boolean (TRUE or FALSE) depending or not the user is logged in. Essentially, it does the same thing as the first example, but there's no need to load the global variable. This returns a boolean (TRUE or FALSE) depending or not the user is logged in. Essentially, it does the same thing as the first example, but there's no need to load the global variable.
A great use case for this is within a `hook_menu()` implementation within a custom module. A great use case for this is within a `hook_menu()` implementation within a custom module.
~~~~ ```language-php
/** /**
* Implements hook_menu(). * Implements hook_menu().
*/ */
@ -58,7 +58,7 @@ function mymodule_menu() {
return $items; return $items;
} }
~~~~ ```
There is also a [user_is_anonymous()](http://api.drupal.org/api/drupal/modules!user!user.module/function/user_is_anonymous/7) function if you want the opposite result. Both of these functions are available in Drupal 6 and higher. There is also a [user_is_anonymous()](http://api.drupal.org/api/drupal/modules!user!user.module/function/user_is_anonymous/7) function if you want the opposite result. Both of these functions are available in Drupal 6 and higher.
{% endblock %} {% endblock %}

View file

@ -32,7 +32,7 @@ We will be using the fictional *foo* module to demonstrate this.
The first thing that we need to do is define the new token type and/or the token itself, along with it's descriptive text. To view the existing tokens and types, use `dpm(token_get_info());`, assuming that you have the [Devel module](http://drupal.org/project/devel) installed. The first thing that we need to do is define the new token type and/or the token itself, along with it's descriptive text. To view the existing tokens and types, use `dpm(token_get_info());`, assuming that you have the [Devel module](http://drupal.org/project/devel) installed.
~~~php ```language-php
/** /**
* Implements hook_token_info(). * Implements hook_token_info().
*/ */
@ -45,7 +45,7 @@ function foo_token_info() {
// Return them. // Return them.
return $info; return $info;
} }
~~~ ```
In this case, the token called *bar* resides within the *foo* group. In this case, the token called *bar* resides within the *foo* group.
@ -55,7 +55,7 @@ If I needed to add a new token within an existing token type, such as 'node', th
Now that the Token module is aware of our new token, we now need to determine what the token is replaced with. This is done using `hook_tokens()`. Here is the basic code needed for an implementation: Now that the Token module is aware of our new token, we now need to determine what the token is replaced with. This is done using `hook_tokens()`. Here is the basic code needed for an implementation:
~~~php ```language-php
/** /**
* Implements hook_tokens(). * Implements hook_tokens().
*/ */
@ -67,11 +67,11 @@ function foo_tokens($type, $tokens, array $data = array(), array $options = arra
// Return the replacements. // Return the replacements.
return $replacements; return $replacements;
} }
~~~ ```
The first thing to check for is the type of token using an `if()` function, as this could be an existing type like 'node', 'user' or 'site', or a custom token type like 'foo'. Once we're sure that we're looking at the right type(s), we can use `foreach ($tokens as $name => $original)` to loop through each of the available tokens using a `switch()`. For each token, you can perform some logic to work out the replacement text and then add it into the replacements array using `$replacements[$original] = $new;`. The first thing to check for is the type of token using an `if()` function, as this could be an existing type like 'node', 'user' or 'site', or a custom token type like 'foo'. Once we're sure that we're looking at the right type(s), we can use `foreach ($tokens as $name => $original)` to loop through each of the available tokens using a `switch()`. For each token, you can perform some logic to work out the replacement text and then add it into the replacements array using `$replacements[$original] = $new;`.
~~~php ```language-php
/** /**
* Implements hook_tokens(). * Implements hook_tokens().
*/ */
@ -100,13 +100,13 @@ function foo_tokens($type, $tokens, array $data = array(), array $options = arra
// Return the replacements. // Return the replacements.
return $replacements; return $replacements;
} }
~~~ ```
## Example ## Example
An example from Copyright Block module: An example from Copyright Block module:
~~~php ```language-php
/** /**
* Implements hook_tokens(). * Implements hook_tokens().
*/ */
@ -128,17 +128,17 @@ function copyright_block_tokens($type, $tokens, array $data = array(), array $op
return $replacements; return $replacements;
} }
~~~ ```
## Using token_replace() ## Using token_replace()
With everything defined, all that we now need to do is pass some text through the `token_replace()` function to replace it with the values defined within `hook_token()`. With everything defined, all that we now need to do is pass some text through the `token_replace()` function to replace it with the values defined within `hook_token()`.
~~~php ```language-php
$a = t('Something'); $a = t('Something');
// This would use any token type - node, user etc. // This would use any token type - node, user etc.
$b = token_replace($a); $b = token_replace($a);
// This would only use foo tokens. // This would only use foo tokens.
$c = token_replace($a, array('foo')); $c = token_replace($a, array('foo'));
~~~ ```
{% endblock %} {% endblock %}

View file

@ -14,9 +14,11 @@ After reading numerous blog posts about how to install [Sublime Text 2](http://w
{% block content %} {% block content %}
After reading numerous blog posts about how to install [Sublime Text 2](http://www.sublimetext.com/2 "Sublime Text 2") in [Ubuntu](http://www.ubuntu.com/2 "Ubuntu"), this is definitely the quickest way! Just paste the following lines into your Terminal: After reading numerous blog posts about how to install [Sublime Text 2](http://www.sublimetext.com/2 "Sublime Text 2") in [Ubuntu](http://www.ubuntu.com/2 "Ubuntu"), this is definitely the quickest way! Just paste the following lines into your Terminal:
$ sudo add-apt-repository ppa:webupd8team/sublime-text-2 ```language-bash
$ sudo apt-get update $ sudo add-apt-repository ppa:webupd8team/sublime-text-2
$ sudo apt-get install sublime-text $ sudo apt-get update
$ sudo apt-get install sublime-text
```
After running this, Sublime Text 2 has been installed within the */usr/lib/sublime-text-2* directory and can be launched from the Dashboard, or by typing `subl`, `sublime-text` or `sublime-text-2` into a Terminal window. After running this, Sublime Text 2 has been installed within the */usr/lib/sublime-text-2* directory and can be launched from the Dashboard, or by typing `subl`, `sublime-text` or `sublime-text-2` into a Terminal window.
{% endblock %} {% endblock %}

View file

@ -18,20 +18,22 @@ Whilst watching [Drupalize.me](http://drupalize.me "Drupalize.me")'s recent [Int
For example (with some slight modifications): For example (with some slight modifications):
~~~~ ```language-bash
oliver@oliver-mbp:~/Development/drupal(master) $ oliver@oliver-mbp:~/Development/drupal(master) $
oliver@oliver-mbp:~/Development/a11y_checklist(7.x-1.0) $ oliver@oliver-mbp:~/Development/a11y_checklist(7.x-1.0) $
~~~~ ```
Here's how to do it. Here's how to do it.
To begin with, create a new file to contain the functions, To begin with, create a new file to contain the functions,
vim ~/.bash/git-prompt ```language-bash
vim ~/.bash/git-prompt
```
Paste the following code into the file, and save it. Paste the following code into the file, and save it.
~~~~ ```language-bash
parse_git_branch () { parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
} }
@ -47,18 +49,20 @@ parse_git_branch_or_tag() {
fi fi
echo $OUT echo $OUT
} }
~~~~ ```
Edit your `.bashrc` or `.bash_profile` file to override the PS1 value. Edit your `.bashrc` or `.bash_profile` file to override the PS1 value.
vim ~/.bashrc ```language-bash
vim ~/.bashrc
```
Add the following code at the bottom of the file, and save it. Add the following code at the bottom of the file, and save it.
~~~~ ```language-bash
source ~/.bash/git-prompt source ~/.bash/git-prompt
PS1="\u@\h:\w\$(parse_git_branch_or_tag) $ " PS1="\u@\h:\w\$(parse_git_branch_or_tag) $ "
~~~~ ```
Restart your Terminal or type `source ~/.bashrc` to see your changes. Restart your Terminal or type `source ~/.bashrc` to see your changes.
{% endblock %} {% endblock %}

View file

@ -20,15 +20,15 @@ The [Domain Access project](https://drupal.org/project/domain "The Domain Access
Rather than changing the domain settings within the Domain module itself, the best solution I think is to use table prefixes and create a different domain table per environment. With a live, staging and local domains, the tables would be named as follows: Rather than changing the domain settings within the Domain module itself, the best solution I think is to use table prefixes and create a different domain table per environment. With a live, staging and local domains, the tables would be named as follows:
~~~~ ```language-bash
live_domain live_domain
local_domain local_domain
staging_domain staging_domain
~~~~ ```
Within each site's settings.php file, define the prefix for the domain table within the databases array so that each site is looking at the correct table for its environment. Within each site's settings.php file, define the prefix for the domain table within the databases array so that each site is looking at the correct table for its environment.
~~~~php ```language-php
$databases['default']['default'] = array( $databases['default']['default'] = array(
'driver' => 'mysql', 'driver' => 'mysql',
'database' => 'foobar', 'database' => 'foobar',
@ -41,7 +41,7 @@ $databases['default']['default'] = array(
// Add any other prefixed tables here. // Add any other prefixed tables here.
), ),
); );
~~~~ ```
Within each environment-specific domain table, update the subdomain column to contain the appropriate domain names. Within each environment-specific domain table, update the subdomain column to contain the appropriate domain names.

View file

@ -16,11 +16,15 @@ How to use [Drush](https://drupal.org/project/drush) to quickly build a new sub-
{% block content %} {% block content %}
First, download the [Zen](https://drupal.org/project/zen "The Zen theme") theme if you haven't already done so. First, download the [Zen](https://drupal.org/project/zen "The Zen theme") theme if you haven't already done so.
$ drush dl zen ```language-bash
$ drush dl zen
```
This will now enable you to use the "drush zen" command. This will now enable you to use the "drush zen" command.
$ drush zen "Oliver Davies" oliverdavies --description="A Zen sub-theme for oliverdavies.co.uk" --without-rtl ```language-bash
$ drush zen "Oliver Davies" oliverdavies --description="A Zen sub-theme for oliverdavies.co.uk" --without-rtl
```
The parameters that I'm passing it are: The parameters that I'm passing it are:

View file

@ -17,7 +17,7 @@ There are times when doing Drupal development when you need to run a custom PHP
To bootstrap Drupal, you would need to add some additional lines of code to the stop of your script. Something like: To bootstrap Drupal, you would need to add some additional lines of code to the stop of your script. Something like:
~~~php ```language-php
<?php <?php
// Bootstrap Drupal. // Bootstrap Drupal.
@ -28,28 +28,32 @@ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Do stuff. // Do stuff.
$node = node_load(1); $node = node_load(1);
~~~ ```
The script would need be placed in the root of your Drupal directory, and you would then have had to open a browser window and visit http://example.com/foo.php to execute it. This is where the "drush php-script" command (or "drush scr" for short) is useful, and can be used to execute the script from the command line. The script would need be placed in the root of your Drupal directory, and you would then have had to open a browser window and visit http://example.com/foo.php to execute it. This is where the "drush php-script" command (or "drush scr" for short) is useful, and can be used to execute the script from the command line.
$ drush scr foo.php ```language-bash
$ drush scr foo.php
```
It also means that I no longer need to manually bootstrap Drupal, so my script is much cleaner. It also means that I no longer need to manually bootstrap Drupal, so my script is much cleaner.
~~~~ ```language-php
<?php
// Just do stuff. // Just do stuff.
$node = node_load(1); $node = node_load(1);
~~~~ ```
I prefer to keep these scripts outside of my Drupal directory in a separate "scripts" directory (with Drupal in a "drupal" directory on the same level). This makes it easier to update Drupal as I don't need to worry about accidentally deleting the additional files. From within the drupal directory, I can now run the following command to go up one level, into the scripts directory and then execute the script. Note that you do not need to include the file extension. I prefer to keep these scripts outside of my Drupal directory in a separate "scripts" directory (with Drupal in a "drupal" directory on the same level). This makes it easier to update Drupal as I don't need to worry about accidentally deleting the additional files. From within the drupal directory, I can now run the following command to go up one level, into the scripts directory and then execute the script. Note that you do not need to include the file extension.
$ drush scr ../scripts/foo ```language-bash
$ drush scr ../scripts/foo
```
Or, if you're using [Drush aliases](http://deeson-online.co.uk/labs/drupal-drush-aliases-and-how-use-them "Drupal, Drush aliases, and how to use them"): Or, if you're using [Drush aliases](http://deeson-online.co.uk/labs/drupal-drush-aliases-and-how-use-them "Drupal, Drush aliases, and how to use them"):
$ drush @mysite.local scr foo ```language-bash
$ drush @mysite.local scr foo
```
If you commonly use the same scripts for different projects, you could also store these within a separate Git repository and checkout the scripts directory using a [Git submodule](http://git-scm.com/book/en/Git-Tools-Submodules "Git Submodules"). If you commonly use the same scripts for different projects, you could also store these within a separate Git repository and checkout the scripts directory using a [Git submodule](http://git-scm.com/book/en/Git-Tools-Submodules "Git Submodules").
{% endblock %} {% endblock %}

View file

@ -17,11 +17,15 @@ Testing a patch file is usually a two-step process. First you download the patch
You can save time and typing by running the two commands on one line: You can save time and typing by running the two commands on one line:
$ curl http://drupal.org/files/[patch-name].patch | git apply -v ```language-bash
$ curl http://drupal.org/files/[patch-name].patch | git apply -v
```
Or, if you don't have curl installed, you can use wget: Or, if you don't have curl installed, you can use wget:
$ wget -q -O - http://drupal.org/files/[patch-name].patch | git apply -v ```language-bash
$ wget -q -O - http://drupal.org/files/[patch-name].patch | git apply -v
```
These commands need to be run within the root of your Git repository (i.e. where the .git directory is). These commands need to be run within the root of your Git repository (i.e. where the .git directory is).

View file

@ -20,23 +20,31 @@ I still maintain a number of Drupal 6 sites and occassionally need to download D
By declarding the core version of Drupal, such as "drupal-6", Drush will download that instead. By declarding the core version of Drupal, such as "drupal-6", Drush will download that instead.
$ drush dl drupal-6 ```language-bash
$ drush dl drupal-6
```
This downloads the most recent stable version of Drupal 6. If you don't want that, you can add the --select and additionally the --all options to be presented with an entire list to chose from. This downloads the most recent stable version of Drupal 6. If you don't want that, you can add the --select and additionally the --all options to be presented with an entire list to chose from.
$ drush dl drupal-6 --select ```language-bash
$ drush dl drupal-6 --select --all $ drush dl drupal-6 --select
$ drush dl drupal-6 --select --all
```
If you want the most recent development version, just type: If you want the most recent development version, just type:
$ drush dl drupal-6.x ```language-bash
$ drush dl drupal-6.x
```
The same can be done for other core versions of Drupal, from Drupal 5 upwards. The same can be done for other core versions of Drupal, from Drupal 5 upwards.
# This will download Drupal 5 ```language-bash
$ drush dl drupal-5 # This will download Drupal 5
# This will download Drupal 8 $ drush dl drupal-5
$ drush dl drupal-8 # This will download Drupal 8
$ drush dl drupal-8
```
For a full list of the available options, type "drush help pm-download" into a Terminal window or take a look at the entry on [drush.ws](http://drush.ws/#pm-download, "The entry for pm-download on drush.ws"). For a full list of the available options, type "drush help pm-download" into a Terminal window or take a look at the entry on [drush.ws](http://drush.ws/#pm-download, "The entry for pm-download on drush.ws").
{% endblock %} {% endblock %}

View file

@ -11,23 +11,25 @@ Here are some bash aliases that I use and find helpful for quickly writing Git a
{% block content %} {% block content %}
Here are some bash aliases that I use and find helpful for quickly writing Git and Git Flow commands. These should be placed within your `~/.bashrc` or `~/.bash_profile` file: Here are some bash aliases that I use and find helpful for quickly writing Git and Git Flow commands. These should be placed within your `~/.bashrc` or `~/.bash_profile` file:
alias gi="git init" ```language-bash
alias gcl="git clone" alias gi="git init"
alias gco="git checkout" alias gcl="git clone"
alias gs="git status" alias gco="git checkout"
alias ga="git add" alias gs="git status"
alias gaa="git add --all" alias ga="git add"
alias gc="git commit" alias gaa="git add --all"
alias gcm="git commit -m" alias gc="git commit"
alias gca="git commit -am" alias gcm="git commit -m"
alias gm="git merge" alias gca="git commit -am"
alias gr="git rebase" alias gm="git merge"
alias gps="git push" alias gr="git rebase"
alias gpl="git pull" alias gps="git push"
alias gd="git diff" alias gpl="git pull"
alias gl="git log" alias gd="git diff"
alias gfi="git flow init" alias gl="git log"
alias gff="git flow feature" alias gfi="git flow init"
alias gfr="git flow release" alias gff="git flow feature"
alias gfh="git flow hotfix" alias gfr="git flow release"
alias gfh="git flow hotfix"
```
{% endblock %} {% endblock %}

View file

@ -23,7 +23,9 @@ There is an option that the maintainer can add to the end of their commit messag
For example: For example:
--author="opdavies <opdavies@381388.no-reply.drupal.org>" ```language-bash
--author="opdavies <opdavies@381388.no-reply.drupal.org>"
```
This differs slightly different for each Drupal user, and the code can be found on their Drupal.org profile page. This differs slightly different for each Drupal user, and the code can be found on their Drupal.org profile page.
@ -43,13 +45,15 @@ From the [manual page](http://git-scm.com/docs/git-format-patch):
Here is a section of a patch that I created for the [Metatag module](http://drupal.org/project/metatag) using `git format-patch`: Here is a section of a patch that I created for the [Metatag module](http://drupal.org/project/metatag) using `git format-patch`:
From 80c8fa14de7f4a83c2e70367aab0aedcadf4f3b0 Mon Sep 17 00:00:00 2001 ```language-bash
From: Oliver Davies &lt;oliver@oliverdavies.co.uk&gt; From 80c8fa14de7f4a83c2e70367aab0aedcadf4f3b0 Mon Sep 17 00:00:00 2001
Date: Mon, 12 May 2014 14:53:55 +0100 From: Oliver Davies &lt;oliver@oliverdavies.co.uk&gt;
Subject: [PATCH] Exclude comment entities when checking if this is the page, Date: Mon, 12 May 2014 14:53:55 +0100
Subject: [PATCH] Exclude comment entities when checking if this is the page,
otherwise comment_fragment.module will break metatag otherwise comment_fragment.module will break metatag
--- ---
```
As mentioned above, the patch is structured in an email format. The commit message is used as the subject line, and the date that the commit was made locally is used for the date. What were interested in is the “From” value. This contains your name and email address from your `~/.gitconfig` file and is used to author the patch automatically. As mentioned above, the patch is structured in an email format. The commit message is used as the subject line, and the date that the commit was made locally is used for the date. What were interested in is the “From” value. This contains your name and email address from your `~/.gitconfig` file and is used to author the patch automatically.
@ -78,15 +82,19 @@ If you need to commit a patch that was created using `git format-patch`, the bes
For example, within your repository, run: For example, within your repository, run:
$ git am /path/to/file ```language-bash
$ git am ~/Code/metatag-comment-fragment-conflict-2265447-4.patch $ git am /path/to/file
$ git am ~/Code/metatag-comment-fragment-conflict-2265447-4.patch
```
You should end up with some output similar to the following: You should end up with some output similar to the following:
Applying: #2272799 Added supporters section ```language-bash
Applying: #2272799 Added navigation tabs Applying: #2272799 Added supporters section
Applying: #2272799 Fixed indentation Applying: #2272799 Added navigation tabs
Applying: #2272799 Replaced URL Applying: #2272799 Fixed indentation
Applying: #2272799 Replaced URL
```
Each line is the commit message associated with that patch. Each line is the commit message associated with that patch.

View file

@ -32,7 +32,9 @@ Once you have a list of the components that you need to add, you can export the
For example: For example:
$ drush features-export -y myfeature field_base:field_foo field_instance:user-field_foo ```language-bash
$ drush features-export -y myfeature field_base:field_foo field_instance:user-field_foo
```
In this example, the base for field_boo and it's instance on the user object is being added to the "myfeature" feature. In this example, the base for field_boo and it's instance on the user object is being added to the "myfeature" feature.

View file

@ -16,7 +16,7 @@ How to use an @each loop in SASS to quickly include multiple font files within y
{% block content %} {% block content %}
Using a file structure similar to this, organise your font files into directories, using the the font name for both the directory name and for the file names. Using a file structure similar to this, organise your font files into directories, using the the font name for both the directory name and for the file names.
~~~~ ```language-bash
. .
├── FuturaBold ├── FuturaBold
│ ├── FuturaBold.eot │ ├── FuturaBold.eot
@ -38,11 +38,11 @@ Using a file structure similar to this, organise your font files into directorie
│ ├── FuturaItalic.svg │ ├── FuturaItalic.svg
│ ├── FuturaItalic.ttf │ ├── FuturaItalic.ttf
│ └── FuturaItalic.woff │ └── FuturaItalic.woff
~~~~ ```
Within your SASS file, start an `@each` loop, listing the names of the fonts. In the same way as PHP's `foreach` loop, each font name will get looped through using the `$family` variable and then compiled into CSS. Within your SASS file, start an `@each` loop, listing the names of the fonts. In the same way as PHP's `foreach` loop, each font name will get looped through using the `$family` variable and then compiled into CSS.
~~~~ ```language-scss
@each $family in FuturaBook, FuturaBold, FuturaBoldItalic, FuturaItalic { @each $family in FuturaBook, FuturaBold, FuturaBoldItalic, FuturaItalic {
@font-face { @font-face {
font-family: #{$family}; font-family: #{$family};
@ -55,9 +55,11 @@ Within your SASS file, start an `@each` loop, listing the names of the fonts. In
font-style: normal; font-style: normal;
} }
} }
~~~~ ```
When the CSS has been compiled, you can then use in your CSS in the standard way. When the CSS has been compiled, you can then use in your CSS in the standard way.
font-family: "FuturaBook"; ```language-scss
font-family: "FuturaBook";
```
{% endblock %} {% endblock %}

View file

@ -15,7 +15,7 @@ Download the [Stage File Proxy](https://www.drupal.org/project/stage_file_proxy)
As this module is only going to be needed on pre-production sites, it would be better to configure this within your settings.php or settings.local.php file. We do this using the `$conf` array which removes the need to configure the module through the UI and store the values in the database. As this module is only going to be needed on pre-production sites, it would be better to configure this within your settings.php or settings.local.php file. We do this using the `$conf` array which removes the need to configure the module through the UI and store the values in the database.
~~~php ```language-php
// File proxy to the live site. // File proxy to the live site.
$conf['stage_file_proxy_origin'] = 'http://www.example.com'; $conf['stage_file_proxy_origin'] = 'http://www.example.com';
@ -24,11 +24,11 @@ $conf['stage_file_proxy_hotlink'] = TRUE;
// Image style images are the wrong size otherwise. // Image style images are the wrong size otherwise.
$conf['stage_file_proxy_use_imagecache_root'] = FALSE; $conf['stage_file_proxy_use_imagecache_root'] = FALSE;
~~~ ```
If the origin site is not publicly accessible yet, maybe it's a pre-live or staging site, and protected with a basic access authentication, you can include the username and password within the origin URL. If the origin site is not publicly accessible yet, maybe it's a pre-live or staging site, and protected with a basic access authentication, you can include the username and password within the origin URL.
~~~php ```language-php
$conf['stage_file_proxy_origin'] = 'http://user:password@prelive.example.com'; $conf['stage_file_proxy_origin'] = 'http://user:password@prelive.example.com';
~~~ ```
{% endblock %} {% endblock %}

View file

@ -19,7 +19,7 @@ I was recently doing some work on a site hosted on [Pantheon](http://getpantheon
The way that was recommended was by using a `switch()` function based on Pantheon's environment variable. For example: The way that was recommended was by using a `switch()` function based on Pantheon's environment variable. For example:
~~~php ```language-php
switch ($_SERVER['PANTHEON_ENVIRONMENT']) { switch ($_SERVER['PANTHEON_ENVIRONMENT']) {
case 'dev': case 'dev':
// Development environment. // Development environment.
@ -38,7 +38,7 @@ switch ($_SERVER['PANTHEON_ENVIRONMENT']) {
$base_url = 'live-my-site.gotpantheon.com'; $base_url = 'live-my-site.gotpantheon.com';
break; break;
} }
~~~ ```
Whilst this works, it doesn't conform to the DRY (don't repeat yourself) principle and means that you also might get a rather long and complicated settings file, especially when you start using multiple switches and checking for the value of the environment multiple times. Whilst this works, it doesn't conform to the DRY (don't repeat yourself) principle and means that you also might get a rather long and complicated settings file, especially when you start using multiple switches and checking for the value of the environment multiple times.
@ -46,7 +46,7 @@ My alternative solution to this is to include an environment-specific settings f
To do this, add the following code to the bottom of settings.php: To do this, add the following code to the bottom of settings.php:
~~~php ```language-php
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) { if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
if ($_SERVER['PANTHEON_ENVIRONMENT'] != 'live') { if ($_SERVER['PANTHEON_ENVIRONMENT'] != 'live') {
// You can still add things here, for example to apply to all sites apart // You can still add things here, for example to apply to all sites apart
@ -60,7 +60,7 @@ if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
include $environment_settings; include $environment_settings;
} }
} }
~~~ ```
This means that rather than having one long file, each environment has it's own dedicated settings file that contains it's own additional configuration. This is much easier to read and make changes to, and also means that less code is loaded and parsed by PHP. Settings that apply to all environments are still added to settings.php. This means that rather than having one long file, each environment has it's own dedicated settings file that contains it's own additional configuration. This is much easier to read and make changes to, and also means that less code is loaded and parsed by PHP. Settings that apply to all environments are still added to settings.php.
@ -68,7 +68,7 @@ Below this, I also include a [similar piece of code](/blog/include-local-drupal-
Within the sites/default directory, I also include an example file (example.settings.env.php) for reference. This is duplicated, renamed and populated accordingly. Within the sites/default directory, I also include an example file (example.settings.env.php) for reference. This is duplicated, renamed and populated accordingly.
~~~php ```language-php
<?php <?php
/** /**
@ -83,7 +83,7 @@ Within the sites/default directory, I also include an example file (example.sett
*/ */
$base_url = ''; $base_url = '';
~~~ ```
The environment specific files are also committed into Git and pushed to Pantheon, and are then included automatically on each environment. The environment specific files are also committed into Git and pushed to Pantheon, and are then included automatically on each environment.
{% endblock %} {% endblock %}

View file

@ -17,12 +17,12 @@ How to create and include a local settings file to define and override environme
{% block content %} {% block content %}
At the bottom of settings.php, add the following code: At the bottom of settings.php, add the following code:
~~~php ```language-php
$local_settings = __DIR__ . '/settings.local.php'; $local_settings = __DIR__ . '/settings.local.php';
if (file_exists($local_settings)) { if (file_exists($local_settings)) {
include $local_settings; include $local_settings;
} }
~~~ ```
This allows for you to create a new file called settings.local.php within a sites/* directory (the same place as settings.php), and this will be included as an extension of settings.php. You can see the same technique being used within Drupal 8's [default.settings.php](http://cgit.drupalcode.org/drupal/tree/sites/default/default.settings.php#n621) file. This allows for you to create a new file called settings.local.php within a sites/* directory (the same place as settings.php), and this will be included as an extension of settings.php. You can see the same technique being used within Drupal 8's [default.settings.php](http://cgit.drupalcode.org/drupal/tree/sites/default/default.settings.php#n621) file.
@ -30,18 +30,20 @@ Environment specific settings like `$databases` and `$base_url` can be placed wi
settings.php though is ignored by default by Git by a .gitignore file, so it won't show up as a file available to be committed. There are two ways to fix this. The first is to use the `--force` option when adding the file which overrides the ignore file: settings.php though is ignored by default by Git by a .gitignore file, so it won't show up as a file available to be committed. There are two ways to fix this. The first is to use the `--force` option when adding the file which overrides the ignore file:
git add --force sites/default/settings.php ```language-bash
git add --force sites/default/settings.php
```
The other option is to update the .gitignore file itself so that settings.php is no longer ignored. An updated .gitignore file could look like: The other option is to update the .gitignore file itself so that settings.php is no longer ignored. An updated .gitignore file could look like:
~~~ ```language-bash
# Ignore configuration files that may contain sensitive information. # Ignore configuration files that may contain sensitive information.
sites/*/settings.local*.php sites/*/settings.local*.php
# Ignore paths that contain user-generated content. # Ignore paths that contain user-generated content.
sites/*/files sites/*/files
sites/*/private sites/*/private
~~~ ```
This will allow for settings.php to be added to Git and committed, but not settings.local.php. This will allow for settings.php to be added to Git and committed, but not settings.local.php.
{% endblock %} {% endblock %}

View file

@ -22,33 +22,33 @@ As we don't need the module configured on production (we don't need to reroute a
The first thing that we need to do is to enable rerouting. Without doing this, nothing will happen. The first thing that we need to do is to enable rerouting. Without doing this, nothing will happen.
~~~php ```language-php
$conf['reroute_email_enable'] = TRUE; $conf['reroute_email_enable'] = TRUE;
~~~ ```
The next option is to whether to show rerouting description in mail body. I usually have this enabled. Set this to TRUE or FALSE depending on your preference. The next option is to whether to show rerouting description in mail body. I usually have this enabled. Set this to TRUE or FALSE depending on your preference.
~~~php ```language-php
$conf['reroute_email_enable_message'] = TRUE; $conf['reroute_email_enable_message'] = TRUE;
~~~ ```
The last setting is the email address to use. If you're entering a single address, you can add it as a simple string. The last setting is the email address to use. If you're entering a single address, you can add it as a simple string.
~~~php ```language-php
$conf['reroute_email_address'] = 'person1@example.com'; $conf['reroute_email_address'] = 'person1@example.com';
~~~ ```
In this example, all emails from the site will be rerouted to person1@example.com. In this example, all emails from the site will be rerouted to person1@example.com.
If you want to add multiple addresses, these should be added in a semicolon-delimited list. Whilst you could add these also as a string, I prefer to use an array of addresses and the `implode()` function. If you want to add multiple addresses, these should be added in a semicolon-delimited list. Whilst you could add these also as a string, I prefer to use an array of addresses and the `implode()` function.
~~~php ```language-php
$conf['reroute_email_address'] = implode(';', array( $conf['reroute_email_address'] = implode(';', array(
'person1@example.com', 'person1@example.com',
'person2@example.com', 'person2@example.com',
'person3@example.com', 'person3@example.com',
)); ));
~~~ ```
In this example, person2@example.com and person3@example.com would receive their emails from the site as normal. Any emails to addresses not in the array would continue to be redirected to person1@example.com. In this example, person2@example.com and person3@example.com would receive their emails from the site as normal. Any emails to addresses not in the array would continue to be redirected to person1@example.com.
{% endblock %} {% endblock %}

View file

@ -26,7 +26,9 @@ What I'm going to be doing for my contrib projects is defining a minimum version
You can define a simple dependency for your module by adding a line this this to your project's .info file: You can define a simple dependency for your module by adding a line this this to your project's .info file:
dependencies[] = views ```language-bash
dependencies[] = views
```
This would make your module dependant on having the [Views](https://www.drupal.org/project/views) module present and enabled, which you'd need if you were including views as part of your module, for example. This would make your module dependant on having the [Views](https://www.drupal.org/project/views) module present and enabled, which you'd need if you were including views as part of your module, for example.
@ -34,12 +36,16 @@ This would make your module dependant on having the [Views](https://www.drupal.o
In the previous example, our module would enable if _any_ version of Views was enabled, but we need to specify a specific version. We can do this by including version numbers within the dependencies field in the following format: In the previous example, our module would enable if _any_ version of Views was enabled, but we need to specify a specific version. We can do this by including version numbers within the dependencies field in the following format:
dependencies[] = modulename (major.minor) ```language-bash
dependencies[] = modulename (major.minor)
```
This can be a for a specific module release or a branch name: This can be a for a specific module release or a branch name:
dependencies[] = modulename (1.0) ```language-bash
dependencies[] = modulename (1.x) dependencies[] = modulename (1.0)
dependencies[] = modulename (1.x)
```
We can also use the following as part of the field for extra granularity: We can also use the following as part of the field for extra granularity:
@ -52,7 +58,9 @@ We can also use the following as part of the field for extra granularity:
In the original scenario, we want to specify that the module can only be enabled on Drupal core 7.36 or later. To do this, we can use the "greater than or equal to" option. In the original scenario, we want to specify that the module can only be enabled on Drupal core 7.36 or later. To do this, we can use the "greater than or equal to" option.
dependencies[] = system (>=7.36) ```language-ini
dependencies[] = system (>=7.36)
```
Because we need to check for Drupal's core version, we're using the system module as the dependency and specifying that it needs to be either equal to or greater than 7.36. If this dependency is not met, e.g. Drupal 7.35 is being used, then the module cannot be enabled rather than showing a function not found error for `user_has_role()` when it is called. Because we need to check for Drupal's core version, we're using the system module as the dependency and specifying that it needs to be either equal to or greater than 7.36. If this dependency is not met, e.g. Drupal 7.35 is being used, then the module cannot be enabled rather than showing a function not found error for `user_has_role()` when it is called.

View file

@ -27,24 +27,28 @@ There had been commits to the main repo since my pull request was merged, I didn
I had a quick look for a *Update my fork* button or something, but couldn't see one to I added the main repository as an additional remote called `upstream` and fetched the changes. I had a quick look for a *Update my fork* button or something, but couldn't see one to I added the main repository as an additional remote called `upstream` and fetched the changes.
$ git remote add upstream https://github.com/sculpin/sculpin.io.git ```language-bash
$ git remote add upstream https://github.com/sculpin/sculpin.io.git
$ git fetch upstream $ git fetch upstream
remote: Counting objects: 33, done. remote: Counting objects: 33, done.
remote: Total 33 (delta 6), reused 6 (delta 6), pack-reused 27 remote: Total 33 (delta 6), reused 6 (delta 6), pack-reused 27
Unpacking objects: 100% (33/33), done. Unpacking objects: 100% (33/33), done.
From https://github.com/sculpin/sculpin.io From https://github.com/sculpin/sculpin.io
* [new branch] master -> upstream/master * [new branch] master -> upstream/master
* [new branch] pr/4 -> upstream/pr/4 * [new branch] pr/4 -> upstream/pr/4
```
Now my local site knows about the upstream repo, and I could rebase the changes (`git pull upstream master` should have worked too) and push them back to origin. Now my local site knows about the upstream repo, and I could rebase the changes (`git pull upstream master` should have worked too) and push them back to origin.
$ git rebase upstream/master ```language-bash
First, rewinding head to replay your work on top of it... $ git rebase upstream/master
... First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master. ...
Fast-forwarded master to upstream/master.
$ git push origin master $ git push origin master
```
This seems to have worked OK - the commits are still authored by the correct people and at the correct date and time - and I went ahead and created a new feature branch and pull request based on that master branch. This seems to have worked OK - the commits are still authored by the correct people and at the correct date and time - and I went ahead and created a new feature branch and pull request based on that master branch.

View file

@ -39,15 +39,17 @@ This now that Jenkins would be checking for any updates to the repo each minute,
Within the **Builds** section of the item, I added an *Execute Shell* step, where I could enter a command to execute. Here, I pasted a modified version of the original publish.sh script. Within the **Builds** section of the item, I added an *Execute Shell* step, where I could enter a command to execute. Here, I pasted a modified version of the original publish.sh script.
#!/bin/bash ```language-bash
#!/bin/bash
set -uex set -uex
sculpin generate --env=prod --quiet sculpin generate --env=prod --quiet
if [ $? -ne 0 ]; then echo "Could not generate the site"; exit 1; fi if [ $? -ne 0 ]; then echo "Could not generate the site"; exit 1; fi
rsync -avze 'ssh' --delete output_prod/ prodwww2:/var/www/html/oliverdavies.uk/htdocs rsync -avze 'ssh' --delete output_prod/ prodwww2:/var/www/html/oliverdavies.uk/htdocs
if [ $? -ne 0 ]; then echo "Could not publish the site"; exit 1; fi if [ $? -ne 0 ]; then echo "Could not publish the site"; exit 1; fi
```
This essentially is the same as the original file, in that Sculpin generates the site, and uses rsync to deploy it somewhere else. In my case, `prodwww2` is a Jenkins node (this alias is configured in `/var/lib/jenkins/.ssh/config`), and `/var/www/html/oliverdavies.uk/htdocs` is the directory from where my site is served. This essentially is the same as the original file, in that Sculpin generates the site, and uses rsync to deploy it somewhere else. In my case, `prodwww2` is a Jenkins node (this alias is configured in `/var/lib/jenkins/.ssh/config`), and `/var/www/html/oliverdavies.uk/htdocs` is the directory from where my site is served.
@ -57,25 +59,29 @@ There is some dynamic content on my site, specifically on the Talks page. Each t
The YAML front matter: The YAML front matter:
--- ```language-yaml
... ---
talks: ...
talks:
- title: Test Drive Twig with Sculpin - title: Test Drive Twig with Sculpin
date: 2015-07-24 date: 2015-07-24
location: DrupalCamp North location: DrupalCamp North
--- ---
```
The Twig layout: The Twig layout:
{% raw -%} ```language-twig
{% for talk in talks|reverse if talk.date >= now %} {% raw -%}
{% for talk in talks|reverse if talk.date >= now %}
{# Upcoming talks #} {# Upcoming talks #}
{% endfor %} {% endfor %}
{% for talk in talks if talk.date < now %} {% for talk in talks if talk.date < now %}
{# Previous talks #} {# Previous talks #}
{% endfor%} {% endfor%}
{%- endraw %} {%- endraw %}
```
I also didnt want to have to push an empty commit or manually trigger a job in Jenkins after doing a talk in order for it to be positioned in the correct place on the page, so I also wanted Jenkins to schedule a regular build regardless of whether or not code had been pushed, so ensure that my talks page would be up to date. I also didnt want to have to push an empty commit or manually trigger a job in Jenkins after doing a talk in order for it to be positioned in the correct place on the page, so I also wanted Jenkins to schedule a regular build regardless of whether or not code had been pushed, so ensure that my talks page would be up to date.
@ -97,24 +103,30 @@ Since publishing this post, I've added some more items to the original build scr
### Updating Composer ### Updating Composer
if [ -f composer.json ]; then ```language-bash
if [ -f composer.json ]; then
/usr/local/bin/composer install /usr/local/bin/composer install
fi fi
```
Updates project dependencies via [Composer](https://getcomposer.org/doc/00-intro.md#introduction) if composer.json exists. Updates project dependencies via [Composer](https://getcomposer.org/doc/00-intro.md#introduction) if composer.json exists.
### Updating Sculpin Dependencies ### Updating Sculpin Dependencies
if [ -f sculpin.json ]; then ```language-bash
if [ -f sculpin.json ]; then
sculpin install sculpin install
fi fi
```
Runs `sculpin install` on each build if the sculpin.json file exists, to ensure that the required custom bundles and dependencies are installed. Runs `sculpin install` on each build if the sculpin.json file exists, to ensure that the required custom bundles and dependencies are installed.
### Managing Redirects ### Managing Redirects
if [ -f scripts/redirects.php ]; then ```language-bash
if [ -f scripts/redirects.php ]; then
/usr/bin/php scripts/redirects.php /usr/bin/php scripts/redirects.php
fi fi
```
I've been working on a `redirects.php` script that generates redirects from a .csv file, after seeing similar things in the [Pantheon Documentation](https://github.com/pantheon-systems/documentation) and [That Podcast](https://github.com/thatpodcast/thatpodcast.io) repositories. This checks if that file exists, and if so, runs it and generates the source file containing each redirect. I've been working on a `redirects.php` script that generates redirects from a .csv file, after seeing similar things in the [Pantheon Documentation](https://github.com/pantheon-systems/documentation) and [That Podcast](https://github.com/thatpodcast/thatpodcast.io) repositories. This checks if that file exists, and if so, runs it and generates the source file containing each redirect.

View file

@ -24,7 +24,7 @@ Here are the steps that I took to be able to load, render and embed the form.
The first thing that I needed to do to render the form was to load an empty instance of the entityform using `entityform_empty_load()`. In this example, `newsletter` is the name of my form type. The first thing that I needed to do to render the form was to load an empty instance of the entityform using `entityform_empty_load()`. In this example, `newsletter` is the name of my form type.
```php ```language-php
$form = entityform_empty_load('newsletter'); $form = entityform_empty_load('newsletter');
``` ```
@ -36,8 +36,9 @@ The next step was to be able to render the form. I did this using the `entity_fo
As this function is within the `entityform.admin.inc` file and not autoloaded by Drupal, I needed to include it using `module_load_include()` so that the function was available. As this function is within the `entityform.admin.inc` file and not autoloaded by Drupal, I needed to include it using `module_load_include()` so that the function was available.
```php ```language-php
module_load_include('inc', 'entityform', 'entityform.admin'); module_load_include('inc', 'entityform', 'entityform.admin');
$output = entityform_form_wrapper($form, 'submit', 'embedded'), $output = entityform_form_wrapper($form, 'submit', 'embedded'),
``` ```

View file

@ -21,7 +21,7 @@ It supports both the [PSR-0][3] and [PSR-4][4] standards, as well as providing a
To use it, download and enable it from Drupal.org as you would for any other module, and then add it as a dependency within your module. The xautoload project page suggests including a minimum version in this format: To use it, download and enable it from Drupal.org as you would for any other module, and then add it as a dependency within your module. The xautoload project page suggests including a minimum version in this format:
```ini ```language-ini
dependencies[] = xautoload (>= 7.x-5.0) dependencies[] = xautoload (>= 7.x-5.0)
``` ```
@ -33,7 +33,7 @@ This will ensure that the version of xautoload is 7.x-5.0 or newer.
Here is an example .info file for a migrate module. Here is an example .info file for a migrate module.
```ini ```language-ini
; foo_migrate.info ; foo_migrate.info
name = Foo Migration name = Foo Migration
@ -49,7 +49,7 @@ In this example, each custom migration class is stored in its own file within
One thing that the xautoload module does to enable for the use of wildcards within this syntax. By using wildcards, the module file can be simplified as follows: One thing that the xautoload module does to enable for the use of wildcards within this syntax. By using wildcards, the module file can be simplified as follows:
``` ```language-ini
files[] = includes/**/*.inc files[] = includes/**/*.inc
``` ```
@ -72,7 +72,7 @@ In order to do so, youll need to complete the following steps:
Now your class may look something like this: Now your class may look something like this:
```php ```language-php
<?php <?php
namespace Drupal\foo_migrate\Node; namespace Drupal\foo_migrate\Node;
@ -88,7 +88,7 @@ With these steps completed, any imports within your .info file can be removed as
Within `foo_migrate.migrate.inc`, I can now reference any class names using their full namespace: Within `foo_migrate.migrate.inc`, I can now reference any class names using their full namespace:
```php ```language-php
$node_arguments['ArticleNode'] = array( $node_arguments['ArticleNode'] = array(
'class_name' => 'Drupal\foo_migrate\Node\FooArticleNodeMigration', 'class_name' => 'Drupal\foo_migrate\Node\FooArticleNodeMigration',
'source_type' => 'story', 'source_type' => 'story',

View file

@ -15,7 +15,7 @@ The library contains two classes - `GmailFilter` which is used to create each fi
For example: For example:
```php ```language-php
# test.php # test.php
require __DIR__ '/vendor/autoload.php'; require __DIR__ '/vendor/autoload.php';
@ -47,15 +47,21 @@ Its a simple filter that accepts a boolean and returns `true` or `false` as a
Before: Before:
{% raw %}{{ filter.isArchive ? 'true' : 'false' }}{% endraw %} ```language-twig
{% raw %}{{ filter.isArchive ? 'true' : 'false' }}{% endraw %}
```
After: After:
{% raw %}{{ filter.isArchive|boolean_string }}{% endraw %} ```language-twig
{% raw %}{{ filter.isArchive|boolean_string }}{% endraw %}
```
This can then be used to generate output like this, whereas having blank values would have resulted in errors when importing to Gmail. This can then be used to generate output like this, whereas having blank values would have resulted in errors when importing to Gmail.
<apps:property name='shouldArchive' value='true'/> ```language-xml
<apps:property name='shouldArchive' value='true'/>
```
## Example ## Example

View file

@ -22,7 +22,7 @@ Here are the scripts that Im using - they are slightly different from those i
### composer.json ### composer.json
```json ```language-json
"scripts": { "scripts": {
"clean": "rm -rf output_*/", "clean": "rm -rf output_*/",
"dev": "sculpin generate --clean --no-interaction --server --watch", "dev": "sculpin generate --clean --no-interaction --server --watch",
@ -33,7 +33,7 @@ Here are the scripts that Im using - they are slightly different from those i
Run with `composer run <name>`, e.g. `composer run dev`. Run with `composer run <name>`, e.g. `composer run dev`.
### package.json ### package.json
```json ```language-json
"scripts": { "scripts": {
"init": "yarn && bower install", "init": "yarn && bower install",
"dev": "gulp watch", "dev": "gulp watch",

View file

@ -4,7 +4,8 @@ tags: [nginx]
use: [posts] use: [posts]
--- ---
This is an example of how my Nginx configuration looked to redirect from an old domain to a new one, and also to redirect from the root `example.com` domain to the canonical `www` subdomain. This is an example of how my Nginx configuration looked to redirect from an old domain to a new one, and also to redirect from the root `example.com` domain to the canonical `www` subdomain.
```
```language-nginx
server { server {
listen 80; listen 80;
@ -22,11 +23,15 @@ This was fixed by making a small change to my `return` statement.
Before: Before:
return 301 https://www.example.com$uri; ```language-nginx
return 301 https://www.example.com$uri;
```
After: After:
return 301 https://www.example.com$uri$is_args$args; ```language-nginx
return 301 https://www.example.com$uri$is_args$args;
```
`$is_args` is an empty string if there are no arguments, or a `?` to signify the start of the query string. `$args` then adds the arguments (`$query_string` could also be used with the same result). `$is_args` is an empty string if there are no arguments, or a `?` to signify the start of the query string. `$args` then adds the arguments (`$query_string` could also be used with the same result).

View file

@ -11,7 +11,3 @@
{% include 'post/pager' %} {% include 'post/pager' %}
{% include 'post/about-author' %} {% include 'post/about-author' %}
{% endblock %} {% endblock %}
{% block scripts %}
<script>hljs.initHighlightingOnLoad();</script>
{% endblock %}