Skip to content

Instantly share code, notes, and snippets.

@trentsnippets
trentsnippets / FunctionDescriptionComment.txt
Created April 18, 2013 13:01
Function Description Comment
/**
* Function Name
*
* @param bool|string $foo
*
*/
@trentsnippets
trentsnippets / doc_ready.js
Last active December 16, 2015 09:19
Javascript-Jquery-Document_Ready
jQuery(document).ready(function() {
});
@trentsnippets
trentsnippets / CSS-Comment-Block
Created April 18, 2013 23:36
CSS Comment Block
/*
===========================================*/
@trentsnippets
trentsnippets / SsController
Created June 13, 2013 02:18
Basic Silverstripe Controller layout
<?php
/** Tested 3.0
* Text Page.
* This is all the logic for the Text page.
*/
class TextPage extends Page
{
@trentsnippets
trentsnippets / SS_ContactForm
Last active February 8, 2016 00:02
Create a contact form in Silverstripe where submissions are emailed to admin and saved to database. There are 3 Silverstripe files included in this gist.
<?php
/** Important: When adding a second form to a website the second ModalAdmin extention would not function until I added it's
* Tested: 3.0
* name into the same $managed_models array as the first. I was then able to take it out and have it work on it's own.
* ContactPage.php
* This is all the logic for the Contact page.
*/
class ContactPage extends Page
{
@trentsnippets
trentsnippets / AddInputsToCms_SS.php
Last active December 18, 2015 15:09
Add New Input Fields to the CMS in SIlver Stripe
class HomePage extends Page
{
//Add static db array. This controls new databse fields added to this page type.
//These new columns will auto migrate to the db when running dev/build "flush=1" from the browser
static $db = array(
'HomeHeroTitle' => 'Varchar(100)',
'HomeHeroContent' => 'HTMLVarchar(1000)'
);
@trentsnippets
trentsnippets / AddTabToPage_SS.php
Created June 18, 2013 22:23
ADD A TAB TO A PAGE: Silverstripe. This code will add a tab to an individual page and allow you to populate it with entries. This gist consists of two different php files.
<?php
/** Partners.php
* Partners Page.
* This is all the logic for the Partners page.
*/
class PartnersPage extends Page
{
//Set relationship
public static $has_many = array(
@trentsnippets
trentsnippets / Custom_Post_Type_Loop_WP.php
Created June 20, 2013 11:34
Wordpress Loop for a custom post type.
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
the_content();
@trentsnippets
trentsnippets / silverstripeUploadField.php
Last active December 19, 2015 06:48
Add an upload field to silverstripe
//Add a single upload field to upload one image.
static $has_one = array(
'BackgroundImage' => 'Image'
);
$fields->addFieldToTab('Root.Main', new UploadField('BackgroundImage', 'Background Image'), 'Content');
@trentsnippets
trentsnippets / FormValues.js
Last active December 19, 2015 12:28
This jQuery code will make form values show / hide on click so you can use them as titles.
$(document).ready(function(){
$('form input:text, form textarea').each(function(){
$.data(this, 'default', this.value);
}).focus(function(){
if ($.data(this, 'default') == this.value) {
this.value = '';
}
}).blur(function(){
if (this.value === '') {
this.value = $.data(this, 'default');