Skip to content

Instantly share code, notes, and snippets.

@mynameispj
mynameispj / image.tpl.php
Created June 14, 2013 12:31
Drupal 7, print images from a node
$person = node_load($person_nid);
$image = field_get_items('node', $person, 'field_image');
foreach ($image as $key=>$value) {
$output = field_view_value('node', $person, 'field_image', $image[$key], array(
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail', //place your image style here
'image_link' => 'content',
),
@mynameispj
mynameispj / view.html.erb
Created June 11, 2013 08:26
Rails - each do loop with message if the loop is empty
<% if @project_quantity.each do |quantity| %>
<%= quantity.quantity %>
<% end.empty? %>
0
<% end %>
@mynameispj
mynameispj / view.html.erb
Created June 11, 2013 07:42
Rails - print associated attribute in a View
<%= forecast.project_types.collect { |a| a.title } %>
# a.title will print forecast.project_types.title
@mynameispj
mynameispj / node.tpl.php
Created June 11, 2013 06:30
Print a Drupal 7 Block programmatically
// block_load docs: https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_load/7
// Get the arguments from the second- and third-to-last segments of a block's configure URL
// For instance: /#overlay=admin/structure/block/manage/webform/client-block-150/configure
$block = block_load('webform','client-block-150');
print drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
@mynameispj
mynameispj / module.module
Created June 10, 2013 05:52
Drupal 7: add a custom View Mode
/**
* Implements hook_entity_info_alter().
*/
function MYMODULE_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
}
@mynameispj
mynameispj / application_helper.rb
Created June 2, 2013 00:24
Rails - Easy "active" classes for menu links in Rails
module ApplicationHelper
def current_class?(test_path)
return 'active' if request.path == test_path
''
end
end
@mynameispj
mynameispj / menu.html.erb
Created June 1, 2013 06:28
Rails ".active" link method approach
<%= link_to "account stats", account_path, :class => current_page?(:controller => 'experiments') ? 'active':'' %>
@mynameispj
mynameispj / default.rb
Last active December 16, 2015 12:38
Prettier Rails confirm dialogs
<%= link_to 'Delete this junk', junk_path(j), :method => :delete, :confirm => 'You sure you want to delete this junk?' %>
@mynameispj
mynameispj / css-triangle-mixin.sass
Last active June 13, 2017 20:38
SASS mixin to help build CSS triangles (CSS triangle hat-tip to CSS-Tricks: http://css-tricks.com/snippets/css/css-triangle/)
@mixin css-arrow($color:#000, $size:'5px', $direction:'up')
width: 0
height: 0
@if $direction == 'up'
border-right: $size solid transparent
border-left: $size solid transparent
border-bottom: $size solid $color
@if $direction == 'down'
@mynameispj
mynameispj / responsive-iframe.css
Created April 13, 2013 21:44
Responsive Youtube embeds
.videoWrapper {
position: relative;
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
.videoWrapper iframe {
position: absolute;
top: 0;