Skip to content

Instantly share code, notes, and snippets.

@sineld
Created November 26, 2012 09:59
Show Gist options
  • Select an option

  • Save sineld/4147465 to your computer and use it in GitHub Desktop.

Select an option

Save sineld/4147465 to your computer and use it in GitHub Desktop.
Gravatar Macro for Laravel
<?php
// Source: http://forums.laravel.com/viewtopic.php?pid=20704#p20704
// Here's a handy macro for creating an image tag that links to a gravatar image.
//If these files/folders don't exist, create a 'macros' folder in your application folder, and create an 'html.php' file in the macros folder.
// In application/start.php add this to the end of the file:
require path('app').'macros/html.php';
//inside macros/html.php paste the following:
HTML::macro('gravatar', function($email, $size = 128, $alt = '', $attributes = array()){
$attributes['alt'] = $alt;
return '<img src="http://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size.'" '.HTML::attributes($attributes).' />';
});
// You can then use it anywhere in your code. Here's an example of how I use it to get the logged in users gravatar image:
{{HTML::gravatar(Auth::user()->email, 32, Auth::user()->firstname, array('class' => 'avatar'))}}
// Collin
// Syropia | @syropian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment