Skip to content

Instantly share code, notes, and snippets.

View jbroadway's full-sized avatar

John de Plume jbroadway

View GitHub Profile
@jbroadway
jbroadway / MyNav.php
Created August 27, 2013 19:06
Custom tree structures in Elefant.
<?php // apps/myapp/lib/MyNav.php
class MyNav extends Tree {
public function __construct ($file = null) {
$file = $file ? $file : Appconf::get ('myapp', 'Paths', 'navigation_json');
parent::__construct ($file);
}
}
?>
@jbroadway
jbroadway / Document.php
Created August 21, 2013 16:08
Many-many relations in Elefant.
<?php // apps/test/models/Document.php
namespace test;
class Document extends \Model {
public $table = 'test_document';
public $fields = array (
'types' => array (
'many_many' => 'test\Type',
@jbroadway
jbroadway / Type.php
Created August 21, 2013 15:40
Class for bitwise type value storage.
<?php
namespace myapp;
class Type {
const A = 1;
const B = 2;
const C = 4;
public static function is_a ($type) {
@jbroadway
jbroadway / multiple.html
Created August 20, 2013 20:32
Dynamically populated multiple select in an Elefant CMS form.
<!-- apps/test/views/multiple.html -->
<form method="post" id="{{_form}}">
<select name="type[]" multiple>
{% foreach options as val, label %}
<option value="{{val}}"{% if in_array ($data->val, $data->selected) %} selected{% end %}>{{label}}</option>
{% end %}
</select>
@jbroadway
jbroadway / select.html
Created August 20, 2013 19:58
Dynamically populated select box in an Elefant CMS template.
<!-- apps/test/views/select.html -->
<select name="type">
{% foreach options as val, label %}
<option value="{{val}}"{% if selected == $data->val %} selected{% end %}>{{label}}</option>
{% end %}
</select>
@jbroadway
jbroadway / loops.html
Created July 24, 2013 13:30
Looping examples in Elefant templates
<!-- apps/test/views/loops.html -->
<ul>
{% foreach my_array as my_key, my_value %}
<li>{{my_key}}. {{my_value}}</li>
{% end %}
</ul>
<hr />
@jbroadway
jbroadway / Info.md
Created June 25, 2013 17:08
Example of using Ratchet with Elefant

To install Ratchet, add the following line to the "require" section of the composer.json file found in the root of your Elefant site:

"cboden/Ratchet": "0.2.*"

The section should look like this:

"require": {
	"php": ">=5.3.2",
	"cboden/Ratchet": "0.2.*"
}
@jbroadway
jbroadway / embed.php
Created June 25, 2013 16:40
An example of a simple handler that's listed in Elefant's Dynamic Objects menu.
; <?php /* apps/myapp/conf/embed.php
[myapp/myhandler]
label = "MyApp: My Handler"
; */ ?>
@jbroadway
jbroadway / basic.html
Created May 29, 2013 17:30
Possible "basic" template for Elefant
<!DOCTYPE html>
<html>
<head>
<title>{{ window_title|none }}</title>
<meta charset="{{ i18n.charset }}" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,300" />
{% if detect('mobile') %}
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="/css/mobile.css" />
{% else %}
@jbroadway
jbroadway / Link.php
Last active December 14, 2015 12:38
Alternative link generation proposal for Elefant 2. Note that this also proposes changing line 370 of `lib/I18n.php` to `$this->prefix = '/' . $matches[1];` so that a prefix is set when a URL like `/en` is matched.