Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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' %>
<% } -%>
Sub MyAdd(ByVal strTableName As String, ByRef arrData As Variant)
Dim Tbl As ListObject
Dim NewRow As ListRow
Set Tbl = Worksheets("Cart Conversion").ListObjects(strTableName)
Set NewRow = Tbl.ListRows.Add(AlwaysInsert:=True)
' Handle Arrays and Ranges
If TypeName(arrData) = "Range" Then
NewRow.Range = arrData.Value
@mynameispj
mynameispj / yourmodule.module
Last active August 29, 2015 13:56
Get Drupal 7 comment forms to display error messages on the original node's page
function yourmodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'comment_node_blog_post_form') {
$form['actions']['submit']['#value'] = 'Add Your Comment';
$form['#action'] = '?'. drupal_get_destination();
}
}
@mynameispj
mynameispj / MySQL
Created April 8, 2014 04:12
Drupal 7 - Turn on comments for all nodes in a content type via MySQL
UPDATE node SET comment = 2 WHERE type = 'foo'
UPDATE node_revision SET comment = 2 WHERE nid IN (SELECT nid FROM node WHERE type = 'foo')
//'foo' = the machine name of your content type