How to find stuff

Please use Browser Search or Scroll down.

call and write variables, forward function from model to controller

class PageHolder extends Page { static $db = array ( 'uploaded' => 'boolean', ); // create checkerfield here // and set checkerfield on/off from cms public function countUp(){ //$this->uploaded = 1; //$this->uploaded = 0; $this->write(); $this->writeToStage('Stage'); $this->publish("Stage", "Live"); echo $this->uploaded ; } } class PageHolder_Controller extends Page_Controller { public function test(){ $this->countUp(); } } // put $countUp or $test in ss template to call function

send emails

$e = new Email(); $e->To = "someone@example.com"; $e->Subject = "Hi there"; $e->Body = "Do you even lift bro?"; $e->send();

open external links in new window

change page type to redirector then find the navigation template.ss replace this <a href="$Link" > $MenuTitle.XML </a> with this <a href="$Link" <% if RedirectionType = External %>target="_blank"<% end_if %> > $MenuTitle.XML </a>

install old 2.4 silverstripe version auf localhost

create db, import sql then adjust .htaccess with /newroot (slash is wichtig sonst gibts internal server error) change php version from MAMP to 5.2 (sonst gibts substring error)

reset password

put this in _config.php //Security::setDefaultAdmin('Admin', 'password');

SEO modify breadcrumbs to use navigation label instead of page title

open themes/themename/templates/BreadcrumbsTemplate.ss

<% if Pages %> <% if InSection(home) %><% else %> <li><a href="home/">Home</a></li> <% end_if %> <% loop Pages %> <% if Last %><li class="current">$MenuTitle.XML</li><% else %><li><a href="$Link">$MenuTitle.XML</a></li><% end_if %> <% end_loop %> <% end_if %>

modify metatags

put this in Page.php (Page extends SiteTree)

public function MetaTags($includeTitle = true) { $tags = ""; if($this->MetaDescription) { $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n"; } if($this->ExtraMeta) { $tags .= $this->ExtraMeta . "\n"; } $this->extend('MetaTags', $tags); return $tags; }

put this in page.ss

<!DOCTYPE html> <html lang="<% sprintf(_t('IMAGE','%2.2s'),$Locale.RFC1766) %>"> <head> <% base_tag %> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title>$Title &bull; $SiteConfig.Title</title> $MetaTags() <link rel="stylesheet" href="{$ThemeDir}/css/style.css" /> </head> <body> ...

src

open cms/code/model/SiteTree.php

copy MetaTags function

page.php

extend SiteTree in Page.php with MetaTags(...) function

templates

$MetaTags(false) -> kein <titel></titel> $MetaTags -> mit <titel></titel>

custom metatags info

<meta name="language" content="en-uk"> -> useless! google uses only content: <html lang="en"><head>... <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> -> deprecated, use: <meta charset="utf-8"> instead <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> -> just delete this tag to make it visitble again

Alternative:

mit variables und kein $MetaTags in template

metatitle: $MetaTitle title: $Title metadescription: $MetaDescription metakeywords: $MetaKeywords customMeta: $ExtraMeta Nachteil: kein Feld fuer Generator usw... so just customized sitetree.php

silverstripe forms

userforms

download

https://github.com/silverstripe/silverstripe-userforms

usage

rename to userforms run /dev/build?flush=1 in cms change page type to User Defined Form click form tab and add forms click options tab and add email recipient

create custom template

create UserDefinedForm.ss in templates/Layout

(ev. copy TestPage.ss inhalt) <div id="UserForm"> $Content $Form </div>

to get bannerpagetwo tabs in cms:

change userforms/code/model/UserDefinedForm.php

troubleshoot

declare theme in mysite/_config: SSViewer::set_theme('ThemeName'); when error, templates not found... manually delete all items in cache folder: silverstripe-cache/

src

https://github.com/silverstripe/silverstripe-userforms/issues/38

src

different version

http://addons.silverstripe.org/add-ons/silverstripe/userforms

install

http://blog.arvixe.com/how-to-use-userforms-in-silverstripe-cms/

move content fields to tabs

first remove: $fields->removeFieldFromTab("Root.Main","Title"); $fields->removeFieldFromTab("Root.Main","URLSegment"); $fields->removeFieldFromTab("Root.Main","MenuTitle"); $fields->removeFieldFromTab("Root.Main","Metadata"); then add to tab: $fields->addFieldToTab("Root.NewTab", new TextField('Title','Title')); $fields->addFieldToTab("Root.NewTab", new TextField('URLSegment','URL')); $fields->addFieldToTab("Root.NewTab", new TextField('MenuTitle','Menu title')); add with sections: $fields->addFieldToTab("Root.Main", new ToggleCompositeField('UniqueName', 'Section Name', array( new TextField('HeroTitle', 'Title'), ) ), 'Metadata');

hide content fields for non admins, permissions

// first remove field $fields->removeFieldFromTab("Root.Main","Title"); // if admin if(Permission::check('ADMIN')) { $fields->addFieldToTab("Root.NewTab", new TextField('Title','Title')); }else{ }

hide submenu if parent not active

<% if Menu(2) %> <div class="panel-menu hide-on-print"> <% with Level(2) %> <h3><a href="$Link">$MenuTitle.XML</a></h3> <% end_with %> <ul class="side-nav"> <% if LinkOrSection = section %> <% loop $Menu(2) %> <li class="item-$Pos <% if LinkingMode == current %>active<% end_if %><% if LinkingMode == section %>activesub<% else %>inactivesub<% end_if %> <% if Children %>has-dropdown<% end_if %>"> <a href="$Link"> $MenuTitle.XML </a> <%-- first level --%> <% if Children %> <ul class="dropdown panel-sub "> <% loop Children %> <li class="<% if LinkingMode == current %>active<% end_if %> sub-item-$Pos"> <a href="$Link" class="link-$Pos" title="Go to the $Title.XML page">$MenuTitle.XML</a> </li> <% end_loop %> </ul> <% end_if %> <%-- end first level --%> </li> <% end_loop %> <% end_if %> </ul> </div> <% end_if %>

disable spellchecker in cms

put this in _config.php

// disable spellchecker HtmlEditorConfig::get('cms')->setOption('spellcheck','false');

errorpages

create ErrorPage.ss in themes -> borders -> templates -> ErrorPage

cms file, pdf, doc, upload

put this in page template

static $db = array ( ); static $has_one = array ( 'PrintPdf' => 'File', ); public function getGeneratedCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Main", $PrintPdf = UploadField::create('PrintPdf', _t('PDF_Print_preview.PRINTPDF', 'PrintPdf'))); $PrintPdf->setAllowedMaxFileNumber(1); $PrintPdf->setFolderName('customfolder'); $PrintPdf->setOverwriteWarning(false); //remove content field $fields->removeFieldFromTab("Root.Main","Content"); // remove page infos $fields->removeFieldFromTab("Root.Main","Title"); $fields->removeFieldFromTab("Root.Main","URLSegment"); $fields->removeFieldFromTab("Root.Main","MenuTitle"); $fields->removeFieldFromTab("Root.Main","Metadata"); return $fields; } public function getCMSFields() { $fields = $this->getGeneratedCMSFields(); return $fields; }

put this in ANY ss template

(include php in includes and any page) <% with $Page(TestPageDownload) %> <% if $PrintPdf %> <p class="asdf"> <a href="$PrintPdf.URL" title="Download $PrintPdf.Title" target="_blanc"><img class="leftAlone" title="" src="assets/Uploads/icons-pdf.gif" alt="icons pdf" width="20" height="20" />&nbsp;PDF Download ($PrintPdf.Size)</a> </p> <% end_if %> <% end_with %>

remove fields von CMS

remove default content field

$fields->removeFieldFromTab("Root.Main","Content");

remove meta field

$fields->removeFieldFromTab("Root.Main","Metadata");

remove tab

$fields->removeByName("Admin");

Access control, rollenverteilung, security, users permissions

groups -> based on identity (objects, subjects) roles -> based on activities (permissions)

checklist

create groups, create users, assign them (no permissions! leave everything empty!) create roles: uploader, event_editor with permissions! then click on the group -> tab roles and assign role to group who can view (frontend!): go to parent page and set -> inherit (or anyone) ! who can edit: go to parent page and set -> group to hide content from other groups just create another page, hidden from menus and set VIEW to GROUP create new group: TestGroup permissionstab -> check Access to 'Pages' section create new user: TestUser (user email address as login!) assign to group TestGroup select Test root page -> settings -> set Viewer Groups & Editor Groups -> TestGroup ... create another group/user for Test2 they can now only see their pages! (and all unassigned ones!)

caching

ACHTUNG!! to create new templates caching (in _myconfig) must be disabled!! time reset to 5 sek!

create cache folder

create silverstripe-cache folder in silverstripe root then run /?flush=all

caching objects

<% cached 'superduperfunction', LastEdited %> <% end_cached %> (bei dieser variante gibt es einen refresh, sobald auf speichern geklickt wird) oder (aber hier gibts kein refresh, ohne speichern!) <% cached %> <% end_cached %>

set time out for cache

in _config.php

// set expiration to one hour SS_Cache::set_cache_lifetime($for = 'any', $lifetime = 3600, $priority = 100);

cache if user is logged in

<!-- don't cache if the current user is logged-in --> <% cached unless CurrentUser %> <!-- cache only if the current user is logged-in --> <% cached if CurrentUser %>

clear cache as admin

testpage/?flush=all

src

https://github.com/tractorcow/silverstripe-dynamiccache nice explanations with set time: http://www.balbuss.com/partial-caching/

add infofield in CMS

$fields->addFieldToTab("Root.Main", LiteralField::create('info', _t('TestPage.INFO', '<br /><br /><br /> <p><strong>CUstom Upload </strong> </p> <p>&bull; auf folgenden Link klicken <a href="#" target="_blanc">Upload</a> </p> <p>&bull; auf <strong>Upload</strong> klicken</p> <br /><br /><br />')), 'Content');

add checkbox in cms for style changes

TestPage.php

static $db = array ( 'checker' => 'boolean' ); public function getGeneratedCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Main", CheckboxField::create('checker', _t('TestPage.CHECKER', 'remove yellow frame')), 'Content'); return $fields; } public function getCMSFields() { $fields = $this->getGeneratedCMSFields(); return $fields; }

TestPage.ss

<% if $checker %> $rechts <% else %> <div class="panel-type"> $rechts </div> <% end_if %>

css stylesheets conditionals different page

page.ss

<% if ClassName == Pagename1 %> <link rel="stylesheet" href="{$ThemeDir}/css/test1.css" /> <% else_if ClassName == Pagename2 %> <link rel="stylesheet" href="{$ThemeDir}/css/test2.css" /> <% end_if %>

oder in anderen templates

<% if ClassName = HomePage %> <% include Menu2 %> <% end_if %> <% if InSection(Testpage) %><% else %> <!-- <div class="row"> --> <!-- <div class="large-9 push-3 columns "> --> <!-- <% include Breadcrumbs %> --> <!-- </div> --> <!-- </div> --> <% end_if %>

insert button mit site page get id link ins CMS

<a class="small button expand radius" href="[sitetree_link,id=191]">Book Online</a> <p><a class="small button expand radius" href="[sitetree_link,id=141]" target="_blank">ASDF</a></p> (to get ID, in cms hover over page tree and see status bar)

paste as plain text, remove formatting tinyMCE

myconfig:

HtmlEditorConfig::get('cms')->setOption('paste_text_sticky','true'); HtmlEditorConfig::get('cms')->setOption('paste_text_sticky_default','true'); // add a button to remove formatting HtmlEditorConfig::get('cms')->insertButtonsBefore( 'styleselect', 'removeformat' ); // tel the button which tags it may remove HtmlEditorConfig::get('cms')->setOption( 'removeformat_selector', 'b,strong,em,i,span,ul,li,ins' );

adjust backend css

in editor.css /* Import the common styles from typography like link colors. */ @import 'app.css'; /* We want the backend editor to have a bigger font as well though */ .typography * { font-size: 150% }

put site temporarely offline with under construction message

install

name module underconstruction and put it in root run a dev/build settings -> access -> check under construction edit assets/error-503.html <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Domain.com</title> </head> <body> <h1>Domain.com</h1> <p>Welcome!</p> </body> </html>

update the error page with the current design

delete the error-503.html page in the /assets folder run /dev/build again

src

https://github.com/frankmullenger/silverstripe-underconstruction http://silverstripe-webdevelopment.com/tricks/putting-a-site-temporary-offline/

loops

<% loop Children.Limit(5) %> <% if $MultipleOf(5) %> <div class="unit size1of5 lastUnit"> <% else %> <div class="unit size1of5"> <% end_if %> <article> <h1>$Date.nice</h1> <h2>Variety</h2> <p>$Variety </p> <h2>Vegi</h2> <p>$Vegi</p> <h2>Classic</h2> <p>$Classic</p> </article> </div> <% end_loop %> http://doc.silverstripe.org/framework/en/reference/templates

display date

in page controller

function showTime(){ return date('l jS \of F Y h:i:s A'); } // get all events in the future function CurrentTime(){ return ($events) ? DataObject::get("event", "`date` > CURDATE()", "", "", $num) : false; }

in page template

$showTime or just use $Now $LastEdited $LastEdited.Format(d M Y h:i a)

flexslider responsive slideshow (1030x430)

copy into site root and rename: flexslider run /dev/build add to _config.php: Object::add_extension('Page', 'FlexSliderExtension'); change flexslider/javascript/flexslider.template.js: $ to jQuery add this to ss template (before typography, after main): <div class="line inner content-container unit size1of1 lastUnit"> $FlexSlider(1,1030,430) </div> change this in flexslider/thirdparty/Flexslider/flexslider.css: .flexslider {margin: 2px 0 60px 10px; background: none; border: none; position: relative; zoom: 1;} .flexslider img { -webkit-border-radius: 14px; -moz-border-radius: 14px; -o-border-radius: 14px; border-radius: 14px; }

src

http://www.netefx.de/Silverstripe-flexslider.php

menu structur with merged primary &amp; seconday menu

<nav class="primary"> <span class="nav-open-button">²</span> <ul> <% loop Menu(1) %> <li class="$LinkingMode"><a href="$Link" title="$Title.XML">$MenuTitle</a> <div class="sec"> <% if Children(1) %> <ul> <% loop Children(1) %> <li><a href="$Link" title="$Title.XML">$MenuTitle</a> <% if Children(2) %> <ul> <% loop Children(2) %> <li class="$LinkingMode"><a href="$Link" title="$Title.XML" class="dir">$MenuTitle</a> <% if Children(3) %> <ul> <% loop Children(3) %> <li class="$LinkingMode"><a href="$Link" title="$Title.XML" class="dir">$MenuTitle</a> </li> <% end_loop %> </ul> <% end_if %> </li> <% end_loop %> </ul> <% end_if %> </li> <% end_loop %> </ul> <% end_if %> </div> </li> <% end_loop %> </ul> </nav>

search bar

in mysite/_config.php FulltextSearchable::enable(); then http://localhost:8888/ss/dev/build?flush=all

to adjust for multidevice change layout.css

.search-bar { position: absolute; right: 9px; top: 0; } .tablet-nav .search-bar { position: absolute; right: 28px; top: 85px; }

user forms

download

http://www.silverstripe.org/user-forms-module/

install

rename to userforms, copy to root run dev/build find new pagetype "user defined form" in cms

doc

https://raw.github.com/silverstripe/silverstripe-userforms/master/README.md

multilingual pages translatable

http://www.silverstripe.org/translatable-module/ http://www.silverstripe.org/all-other-modules/show/19176

first set default language

i18n::set_locale('cs_CZ'); /dev/build/?flush=1

then edit _config

//default translation Translatable::set_default_locale('de_DE'); /* restrict the language select dropdown in the admin to only those languages that you will actually use. */ Translatable::set_allowed_locales(array( 'de_DE', //Deutsch 'en_GB', //UK English 'fr_FR', //Franz. 'it_IT' //Ital. ) ); Object::add_extension('SiteTree', 'Translatable'); Object::add_extension('SiteConfig', 'Translatable');

then add new language in backend

backend -> settings -> translations -> set new language!!

Add switcher

flaggen

<% if Translations %> <div id="lang" class="clear"> <ul class="clear"> <% control Translations %> <li> <a href="$Link" hreflang="$Locale.RFC1766" title="$Title - $Locale.Nice"> <img src="$ThemeDir/images/lang-<% sprintf(_t('IMAGE','%2.2s'),$Locale.RFC1766) %>.gif"> </a> </li> <% end_control %> </ul> </div> <% end_if %>

Add images of flags

lang-en.gif lang-de.gif lang-fr.gif lang-it.gif put them into: themes/yourtheme/images flush cache

text only switcher

<% if Translations %> <div id="lang" class="flags"> <ul class="flags"> <% control Translations %> <li> <a href="$Link" hreflang="$Locale.RFC1766" title="$Title - $Locale.Nice"> <% sprintf(_t('IMAGE','%2.2s'),$Locale.RFC1766) %> </a> </li> <% end_control %> </ul> </div> <% end_if %>

switch content per language

<% control Translations %> <% if Locale == "en_US" %> <a href="$Link">English version </a> <% end_if %> <% if Locale == "de_DE" %> <a href="$Link">Deutsche Version</a> <% end_if %> <% end_control %>

url segment

first create complete sitetree for one language then translate all or translate parent (holder) too

documentation

http://www.ssbits.com/tutorials/2011/using-translatable-to-create-a-simple-multilingual-site/ http://doc.silverstripe.org/framework/en/2.3/topics/translation