Skip to content

Instantly share code, notes, and snippets.

View sheadawson's full-sized avatar

SheaDawson sheadawson

View GitHub Profile
@sheadawson
sheadawson / SS_Menu
Created September 18, 2012 04:08
Silverstripe nested navigation
<ul id='nav'>
<% control Menu(1) %>
<% if Children %>
<li id='nav-$ID' class="$LinkingMode $FirstLast">
<a href="$Link">$MenuTitle</a>
<ul class="submenu $LinkingMode">
<% control Children %>
<% if Children %>
<li id='nav-$ID' class="$LinkingMode $FirstLast">
<a href="$Link">$MenuTitle</a>
name: extensions
---
SiteConfig:
extensions:
- CustomSiteConfigExtension
@sheadawson
sheadawson / picturefill.js
Last active April 16, 2019 15:19
picturefill.js + jquery.lazyload
/*
This is a customised version of picturefill.js with the following modifications
1. Before setting the source on the img tag to the appropriate img file, check if the lazyload plugin is defined
2. If so, set the data-original attr of the img instead of the src attr. Also set width and height attrs from the picture span's data-width and data-height attrs.
3. Append the img tag and tell lazyload about it
@sheadawson
sheadawson / ContactBlock.php
Last active September 11, 2016 09:04
SilverStripe Blocks - Block with contact form example
<?php
class ContactBlock extends Block {
/**
* Template accessor for the form
**/
public function ContactForm(){
return $this->getController()->ContactForm();
}
@sheadawson
sheadawson / ContentBlock.php
Created January 14, 2015 04:34
SilverStripe Blocks - Basic ContentBlock example
<?php
class ContentBlock extends Block{
private static $singular_name = 'Content Block';
private static $plural_name = 'Content Blocks';
private static $db = array(
'Title' => 'Varchar(255)',
'Content' => 'HTMLText'
@sheadawson
sheadawson / ss-inline-requirements
Created June 18, 2015 01:34
SilverStripe Custom Requirements - put css and js file contents into the page
<?php
class Page_Controller extends ContentController{
/**
* Require a custom script from a file
* @param string $filepath
* @param bool $addMinLive - prepend .min to file extension if not in dev mode
*/
public function inlineJS($filepath, $addMinLive = true){
if(($addMinLive || $addMinLive != 'false') && !Director::isDev()) $filepath = str_replace('.js', '.min.js', $filepath);
@sheadawson
sheadawson / BetterRequirements.php
Last active May 14, 2016 11:40
Helps with embedding css/js files directly into the page, minified, to save http requests
<?php
/**
* BetterRequirements
*
* This class makes 2 things possible.
* 1) Require minified or non minified version of file based on development environment
* 2) Allows css/js file contents to be pulled into the page, saving on extra requests where appropriate
*
* @package ian-potter
* @author [email protected]
@sheadawson
sheadawson / _ss_environment.default.php
Created December 13, 2015 20:51
SS Environment vhost setup
<?php
// place this file above web root
if(!defined('SS_ENVIRONMENT_TYPE')) define('SS_ENVIRONMENT_TYPE', 'dev');
if(!defined('SS_DEFAULT_ADMIN_USERNAME')) define('SS_DEFAULT_ADMIN_USERNAME', 'admin');
if(!defined('SS_DEFAULT_ADMIN_PASSWORD')) define('SS_DEFAULT_ADMIN_PASSWORD', 'admin');
if(!defined('SS_DATABASE_CLASS')) define('SS_DATABASE_CLASS', 'MySQLDatabase');
if(!defined('SS_DATABASE_SERVER')) define('SS_DATABASE_SERVER', '127.0.0.1');
if(!defined('SS_DATABASE_USERNAME')) define('SS_DATABASE_USERNAME', 'root');
@sheadawson
sheadawson / deploy.local.sh
Last active May 13, 2016 18:56
SilverStripe Simple Bash Deploy
#!/bin/bash
HOST="[email protected] -pxxxx"
if [ ! $1 ]; then
ENVIRONMENT='prod'
else
ENVIRONMENT=${1}
fi
@sheadawson
sheadawson / ImageGallery.php
Last active January 18, 2021 13:10
An example of a Shortcodable DataObject. See https://github.com/sheadawson/silverstripe-shortcodable
<?php
/**
* ImageGallery
*
* An example of a Shortcodable DataObject.
* See https://github.com/sheadawson/silverstripe-shortcodable
**/
class ImageGallery extends DataObject
{
private static $db = array(