PHP code example of kinglozzer / yepnopesilverstripe
1. Go to this page and download the library: Download kinglozzer/yepnopesilverstripe library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kinglozzer / yepnopesilverstripe example snippets
class Page_Controller extends ContentController {
public function init() {
parent::init();
/* Add a single file */
Yepnope::add_files('themes/yourtheme/js/yourjavascript.js');
/* Add an array of files */
Yepnope::add_files(
array(
'themes/yourtheme/css/adminstyles.css',
'themes/yourtheme/css/extrauserstyles.css'
)
);
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
$myFiles = array(
'themes/yourtheme/js/filea.js',
'themes/yourtheme/js/fileb.js'
);
/* Will log 'loaded file' to console twice, once for each resource loaded */
Yepnope::add_files($myFiles, "console.log('loaded file')");
/* Will log 'loaded file' to console once, after both resources have been loaded */
Yepnope::add_files($myFiles, null, "console.log('loaded file')");
/* Will log 'loaded file' twice and 'loaded all files' once to the console */
Yepnope::add_files($myFiles, "console.log('loaded file')", "console.log('loaded all files')");
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
Yepnope::add_test(
'Modernizr.geolocation', // Test if geolocation functionality exists
'regular-styles.css', // If it does (test returns true), load regular style
'geolocation-polyfill.js', // If it doesn't (test returns false), load extra file
'standardfunctions.js', // Load these files regardless of test outcome
"console.log('loaded file')", // Call this function upon loading each resource
"console.log('all files loaded')" // Call this function when all files have been loaded
);
}
}
// Page.php
class Page_Controller extends ContentController {
public function init() {
parent::init();
$myFiles = array(
'themes/yourtheme/js/filea.js',
'themes/yourtheme/js/fileb.js'
);
Yepnope::add_files($myFiles, null, null, 'MyFiles'); // Set the id 'MyFiles'
}
}
// ContactPage.php
class ContactPage_Controller extends Page_Controller {
public function init() {
parent::init();
Yepnope::clear_test('MyFiles'); // Clear the test with id 'MyFiles'
}
}
// Page.php
class Page_Controller extends ContentController {
public function init() {
parent::init();
$myFiles = array('themes/yourtheme/js/filea.js');
Yepnope::add_files($myFiles, null, 'function() { pageInit(); }', 'default'); // Set the id 'default'
}
}
// ContactPage.php
class ContactPage_Controller extends Page_Controller {
public function init() {
parent::init();
Yepnope::get_test('default')->setComplete('function() { contactPageInit(); }'); // Override 'complete' function
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
Yepnope::set_yepnope(false) // Removes built-in
class Page_Controller extends ContentController {
public function init() {
parent::init();
Yepnope::add_files('themes/yourtheme/js/yourjavascript.js');
Yepnope::set_timeout(2000); // Sets error timeout to be 2 seconds
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
Yepnope::add_files('themes/simple/javascript/somescript.js', $this->renderWith('MyCallback'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.