Skip to content

Instantly share code, notes, and snippets.

@mynameispj
mynameispj / rails.html.erb
Created January 20, 2014 03:19
Render Rails partial multiple times
<% 10.times { -%>
<%= render :partial => '/prototype/partials/story-list/story_list_filler' %>
<% } -%>
@mynameispj
mynameispj / pagetpl.php
Last active December 19, 2015 17:29
Drupal 7 -- Node_load and then render() some content
<?php
$front_page = node_load("111");
$page_intro = field_view_field('node',$front_page,'field_page_intro');
print render($page_intro);
?>
@mynameispj
mynameispj / pagetpl.php
Last active December 19, 2015 17:28
Drupal 7 Field Collections - Loop to avoid cruft markup
<?php
$front_page = node_load("1");
foreach ($front_page->field_slideshow_images['und'] as $key => $value) {
$slide = entity_load('field_collection_item', array($value['value']));
$idx = $value['value'];
?>
<div class="rsContent slide">
<img src="<?php print image_style_url('none', $slide[$idx]->field_image['und']['0']['uri']); ?>" class="rsImg">
<div class="projectInfo">
<p><?php print $slide[$idx]->field_title_of_project['und']['0']['value']; ?></p>
@mynameispj
mynameispj / overrides.scss
Created July 7, 2013 01:23
Global Drupal overrides. Props to Jeff Glenn (@jeffaglenn) at Deluge.
/*-------------------------------------------------------------------------------*/
/* GLOBAL / DRUPAL OVERRIDES */
/*-------------------------------------------------------------------------------*/
html {
background: #fff;
}
body {
background: #fff;
color: #111011;
@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 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 / 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?' %>