Skip to content

Instantly share code, notes, and snippets.

@renzofp
Last active March 1, 2018 19:15
Show Gist options
  • Save renzofp/ebcd4045fd1e5401205bc7f97a98f2fa to your computer and use it in GitHub Desktop.
Save renzofp/ebcd4045fd1e5401205bc7f97a98f2fa to your computer and use it in GitHub Desktop.
/*THIS IS A COMPLEMENT TO THE DOCS, WHICH CAN BE FOUND HERE AND SHOULD BE REFERENCED:
https://octobercms.com/docs/cms/themes */
/*
################
OCTOBER SETUP:
https://octobercms.com/docs/console/commands#console-install
################
*/
- Get the installer
/*TERMINAL*/ curl -s https://octobercms.com/api/installer | php
- Now you'll be able to run create-project with october. Go to the folder where you store your sites (in my case cd ~/code), and load october files via composer:
/*REQUIRES COMPOSER*/
/*TERMINAL*/ composer create-project october/october project_name
- Now you're ready to setup the october application. cd to project folder and do:
/*TERMINAL*/ php artisan october:install
- You can run your migrations with the following command
/*TERMINAL*/ php artisan october:up
- If you want to update the application files, plugins and migrate the database, run
/*TERMINAL*/ php artisan october:update
- You can remove demo data:
/*TERMINAL*/ php artisan october:fresh
- When having multiple octobercms applications running on homestead, after changing the folders on homestead.yaml, be sure to run on the homestead folder:
/*TERMINAL*/ vagrant reload --provision
/*
################
OCTOBER BASICS:
https://octobercms.com/docs/cms/themes#introduction
################
*/
- OctoberCMS uses the Twig PHP templating engine
- You can run predefined PHP functions (onInit, onStart and onEnd) at the beginning of each page, with the "PHP code section". Before the html:
==
<?
function onStart()
{
$this['posts'] = ...;
}
?>
== /* https://octobercms.com/docs/cms/themes#php-section */
- Each page, layout and partial follows this structure: configuration, php functions, twig markup:
url = "/page"
layout = "layout name"
==
function onStart() {
$this['posts'] = ...;
}
==
<div class="container">
<div class="row">
{% component "insights" %}
</div>
</div>
- You can edit the objects in the php code section. Objects: this.page, this.layout, this.theme, this.param, this.environment
/* https://octobercms.com/docs/cms/pages#page-variables */
/* https://octobercms.com/docs/markup/this-page */
function onEnd()
{
$this->page->title = 'A different page title';
}
/* which can be accessed like this */
<p>The title of this page is: {{ this.page.title }}</p>
<p>The non edited description of the page is: {{ this.page.description }}
- You can add a css class to each page's body tag with the page object's id, like so:
<body class="page-{{ this.page.id }}"> ---> outputs: page-folder-pagename
- You can access the admin dashboard by going to /backend
- The CMS tab contains the Pages, Partials, Layouts, Content, Assets and Components
- Models and controllers are created within Plugins /* https://octobercms.com/docs/plugin/registration#introduction */
- The Builder plugin is great for creating new Plugins: /* https://www.youtube.com/watch?v=O8f_MZS4E0I */
- Components come from plugins, and are configurable building elements that can be dragged to any page, partial or layout /* https://octobercms.com/docs/cms/components */
- You can customize component's output by clicking on the word component and then on the branch button next to the magnifier in the code viewer
- The Static Pages plugin is great for making pages client-editable /* https://www.youtube.com/watch?v=GbAvLAtDS_0 */
- The Content section works like a custom field in wordpress /* https://octobercms.com/docs/cms/content */
- The plugin Wysiwyg Editors allows you to setup wysiwyg editors anywhere. I used them for content, to allow clients to edit, just like advanced custom fields does in wordpress
- Relationships are defined in each Plugin's Model /* https://octobercms.com/docs/backend/relations#relationship-types */
/*
################
TWIG BASICS
################
*/
- All layout, page, content (.txt if no html is required), partial files end in .htm
- Twig doesn't allow plain PHP in the view files (.htm), but you can include code in specific functions (onInit, onStart and onEnd) in the php code section /* https://octobercms.com/docs/cms/pages#page-life-cycle */
- Foreach loops are written as follows in the view files
/*PHP*/
<?php foreach ($projects as $project) { ?>
<img src="<?php echo $project->image; ?>">
<?php } ?>
/*TWIG*/
{% for project in projects %}
<img src="{{ project.image.path }}">
{% endfor %}
/*
################
TWIG MAIN LAYOUT
################
*/
- Include partial into page: {% partial "name-of-partial-without-.htm" %}
- Include page content that uses layout: {% page %}
- Add assets: src="{{ 'url-from-theme-folder'|theme }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment