Monday, 20 July 2015

Avoid using comma and extra classes - using Sass compiler for CSS

Just seen this little nugget of code on TreeHouse and thought it quite useful for writing tidier code.

Rather than writing

.block, .foo {

  color: orange ;


you can use

.block {

color: orange;


.foo {

@extend .block;

//  the rest of my CSS for foo is already here


Wednesday, 15 July 2015

Drupal 7 using Node Nid to get Entity Data

Ok I'm using this blog as a bit of a code bin.

Here's a quick sample of code if you need to get some Entity data from within - you'll need to add protection against any data not being available.

 * Implements template_preprocess_node(&$variables)

function rcnjobs_preprocess_node(&$variables) {
 $nid = $variables['nid'];

  $this_node = node_load($nid);
  $this_node_wrapper = entity_metadata_wrapper('node', $this_node);
  $recruiter = $this_node_wrapper->field_recruiter_reference->value();
  $recruiter_name = $recruiter->name;

  $location_tid_info = $this_node_wrapper->field_job_location->value();

  $location = $location_tid_info[0]->name;