SlideShare a Scribd company logo
1 of 30
Download to read offline
Zotonic
The Tutorial
Erlang User Conference 2013,
Stockholm
Arjan Scherpenisse - arjan@miraclethings.nl
Zotonic's goals

Maximise the use of hardware
 Frontender friendly

Hit the ground running
So, what's in the box?

Multiple sites
 Admin interface

User management
 Page management

Menu editor
 Commenting
 Image management
 Video embedding

Integrated e-mail
sending + receiving (!)
 API OAuth
 i18n
 SEO modules
 Importer modules
 Mailinglist
Getting technical

The data model
 HTTP request flow

Modules & sites
 URL dispatching

The building blocks
Data model: everything is a thing
ArticleArticle
PersonPerson ImageImage
author depiction
HTTP request flow
Modules

Modules are self-contained:
 Dispatch rules, resources, templates, css, javascript,
images, translations, template filters, actions, validators,
API services, models, …
 Prioritized list
 File lookup mechanism
 Every module can be a gen_server
Notification system
 Is how modules extend and offer functionality
 gen_event-like
 Listen to notifications
 Send notifications:
 notify, notify1, fold, map, first
 Both sync and async
% @doc Check if the recipient is a known user, if so redirect the received
e-mail
observe_email_received(#email_received{localpart=Recipient} = Received,
Context) ->
case m_identity:lookup_by_username(Recipient, Context) of
undefined ->
undefined;
Props ->
case proplists:get_value(is_verified, Props) of
true ->
URL dispatching

Dispatch rules per site
 (and per module)

Dispatch rules have names
 e.g. this rule serves the contact.tpl on the /contact
URL:
{contact,
[“contact”], controller_template, [ {template, "contact.tpl"} ]},
The page controller

Webmachine entrypoint for pages
 404 check

Authorization check + logon redirect
 Template selection
Template system

Extended ErlyDTL
 Expressions: {% if a + b > c %}
 Tuple and list data types
 Data access through models: {{ m.rsc[id].title }}

Templates can be made more specific by category
and/or unique page name
 Templates with the same name override each
other
 Uses module priority
Template ex.: page.page_projects.tpl
{% extends "page.tpl" %}
{% block content_body %}
{% cache 7200 %}
{% for r in m.search[{archive_year cat='project'}] %}
<div class="grid_9 alpha omega">
<h2 class="year">{{ r.year }}</h2>
</div>
{% for group in m.search[{query publication_year=r.year|append:""
cat='project'
sort="-publication_start"}]|chunk:3 %}
<div class="grid_9 alpha omega">
{% for id in group %}
{% catinclude "inc/listitem.tpl" id alpha=forloop.first
omega=forloop.last%}
{% endfor %}
</div>
{% endfor %}
{% endfor %}
{% endcache %}
{% endblock %}
Scomps — screen components

For when you need more logic than a template can
handle
 Erlang module
 Cacheable
 Example: {% menu id=id %}
Javascript — Event handling

Ajax postbacks
 Form submits

Calls event/2 function
 Communicates back to browser by sending
javascript
 Inspired by Nitrogen
{% button postback={click foo=”bar”} text=”click me” %}
event({postback, {click, Args}, _Trigger, _Target}, Context) ->
z_render:wire({alert, [{text,”hello”}]}, Context).
Javascript — Push connections

Uses either Comet or WebSockets
 Attaches to the page process

Transports Javascript to the UA
REST services

API method is an Erlang module
 /api/mymodule/mymethod

In /services module directory
 JSON input / output

Process GET and POST
Hands on!

Get Vagrant (version >= 1.1!)
 Clone:
git clone
https://github.com/arjan/zotonic-vagrant-tutorial.git
 Get it running
vagrant up
 … get some coffee...
 Visit: http://localhost:8000
 ...you can also run it on your local machine,
outside vagrant
Let's start!
Tutorial use case: Portfolio site

Site with information about your projects
 Each project has:
 Title, text
 Slide show of large images
 List of related projects
Easy development

apt-get install inotify-tools
 Enable mod_development

Emacs' zotonic-tpl-mode for editing templates
 … and of course erlang-mode / flymake-mode

Each step of this tutorial is a git tag! e.g.
git checkout step-0
#0 – base site

This is what we started with, created using:
 zotonic addsite -L -s basesite tutorial
#1 – create project category
Define the our site-specific domain model:
specific categories that this site uses.

In the site's module (tutorial.erl), we create
manage_schema/2
 Returns a #datamodel{} record
 When done:
 z:m(), z:flush().
 Click “reinstall data model” button in the admin
#2 – create project page template
Create a page specific for resources of the
category project.

Template name: page.project.tpl
 Loops through the list of images
 Note: look at templates/tablet/page.tpl in mod_base_site to see the
template block names that you can use
#3 – project list
A list of recent projects, ordered by their
publication date
 The easy way:
 Create resource with category “search query”
 Search query: “cat=project sort=-publication_start”
 Give it the page path “/projects”
 This can go in your #datamodel{}

#3b – alternative project list
 The hard(coded) way:
 Set up new dispatch rule for /all-projects
 Create all-projects.tpl, write template code...
 (git checkout step-3b)
#4 – feedback form
A form which sends an email to the site
administrator.

Add form to page.project.tpl
 Create event handler in tutorial.erl
 Takes form data,
 Sends email
 Email is HTML; rendered from template
#5 – notification system
We want to make sure a project always has at
least one edge of type “author”

create observe_rsc_update_done/2 in tutorial.erl
 Tip: Look in zotonic_notifications.hrl for more hooks into
the system!

Add code
 Test it in the admin!
 (reload after save to see the new edge)
Thank you!

Please come to my talk on friday!
 “Making it fast” - the performance of Zotonic
 … or chat with me & Andreas :-)
 Online resources:
 http://zotonic.com
 http://zotonic.com/docs
 IRC, XMPP, mailing lists
 Tutorial source code, tutorial slides

More Related Content

What's hot (20)

Ajax
AjaxAjax
Ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Advantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client applicationAdvantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client application
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Ajax Introduction Presentation
Ajax   Introduction   PresentationAjax   Introduction   Presentation
Ajax Introduction Presentation
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 

Viewers also liked

KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!2600Hz
 
Arava Sites By Guy
Arava Sites By GuyArava Sites By Guy
Arava Sites By GuyGZ-Israel
 
Alice Quick Guide
Alice Quick GuideAlice Quick Guide
Alice Quick GuideKJSROSE
 
Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011Arjan
 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceArjan
 
Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8GZ-Israel
 
Ezvc
EzvcEzvc
Ezvcezvc
 
Seica o basilisco é animal de compaña
Seica o basilisco é animal de compañaSeica o basilisco é animal de compaña
Seica o basilisco é animal de compañaGZ-Israel
 
Tel Aviv 1920 1940
Tel Aviv 1920 1940Tel Aviv 1920 1940
Tel Aviv 1920 1940GZ-Israel
 
O mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos PenelaO mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos PenelaGZ-Israel
 
O Meu Pequeno Pais
O Meu Pequeno PaisO Meu Pequeno Pais
O Meu Pequeno PaisGZ-Israel
 
Android workshop
Android workshopAndroid workshop
Android workshopArjan
 
Mark Chagall
Mark ChagallMark Chagall
Mark ChagallGZ-Israel
 
Mediamatic Night Lab #2
Mediamatic Night Lab #2Mediamatic Night Lab #2
Mediamatic Night Lab #2Arjan
 
Israel 1214781329718633 9
Israel 1214781329718633 9Israel 1214781329718633 9
Israel 1214781329718633 9GZ-Israel
 
El Pueblo Gallego 1948
El Pueblo Gallego 1948El Pueblo Gallego 1948
El Pueblo Gallego 1948GZ-Israel
 
Tweets polls surveys
Tweets polls surveysTweets polls surveys
Tweets polls surveysSandra Hines
 

Viewers also liked (20)

KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!
 
Arava Sites By Guy
Arava Sites By GuyArava Sites By Guy
Arava Sites By Guy
 
Alice Quick Guide
Alice Quick GuideAlice Quick Guide
Alice Quick Guide
 
Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011Zotonic presentation Erlang Camp Boston, august 2011
Zotonic presentation Erlang Camp Boston, august 2011
 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang dance
 
IPsec
IPsecIPsec
IPsec
 
Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8Israelair Photos 1214209899278185 8
Israelair Photos 1214209899278185 8
 
Ezvc
EzvcEzvc
Ezvc
 
Seica o basilisco é animal de compaña
Seica o basilisco é animal de compañaSeica o basilisco é animal de compaña
Seica o basilisco é animal de compaña
 
Rami Meiri
Rami MeiriRami Meiri
Rami Meiri
 
Tel Aviv 1920 1940
Tel Aviv 1920 1940Tel Aviv 1920 1940
Tel Aviv 1920 1940
 
O mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos PenelaO mar desde esa banda. De Carlos Penela
O mar desde esa banda. De Carlos Penela
 
O Meu Pequeno Pais
O Meu Pequeno PaisO Meu Pequeno Pais
O Meu Pequeno Pais
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Mark Chagall
Mark ChagallMark Chagall
Mark Chagall
 
Maketechwork4u
Maketechwork4uMaketechwork4u
Maketechwork4u
 
Mediamatic Night Lab #2
Mediamatic Night Lab #2Mediamatic Night Lab #2
Mediamatic Night Lab #2
 
Israel 1214781329718633 9
Israel 1214781329718633 9Israel 1214781329718633 9
Israel 1214781329718633 9
 
El Pueblo Gallego 1948
El Pueblo Gallego 1948El Pueblo Gallego 1948
El Pueblo Gallego 1948
 
Tweets polls surveys
Tweets polls surveysTweets polls surveys
Tweets polls surveys
 

Similar to Zotonic tutorial EUC 2013

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 
Serverless ML Workshop with Hopsworks at PyData Seattle
Serverless ML Workshop with Hopsworks at PyData SeattleServerless ML Workshop with Hopsworks at PyData Seattle
Serverless ML Workshop with Hopsworks at PyData SeattleJim Dowling
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
Custom Forms and Configuration Forms in Drupal 8
Custom Forms and Configuration Forms in Drupal 8Custom Forms and Configuration Forms in Drupal 8
Custom Forms and Configuration Forms in Drupal 8Italo Mairo
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSAkshay Mathur
 
Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Tobias Mattsson
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018Microsoft 365 Developer
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component PatternsMatthew Beale
 
CCCDjango2010.pdf
CCCDjango2010.pdfCCCDjango2010.pdf
CCCDjango2010.pdfjayarao21
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic IntroductionLearningTech
 

Similar to Zotonic tutorial EUC 2013 (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
Serverless ML Workshop with Hopsworks at PyData Seattle
Serverless ML Workshop with Hopsworks at PyData SeattleServerless ML Workshop with Hopsworks at PyData Seattle
Serverless ML Workshop with Hopsworks at PyData Seattle
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Custom Forms and Configuration Forms in Drupal 8
Custom Forms and Configuration Forms in Drupal 8Custom Forms and Configuration Forms in Drupal 8
Custom Forms and Configuration Forms in Drupal 8
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JS
 
Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015Spring first in Magnolia CMS - Spring I/O 2015
Spring first in Magnolia CMS - Spring I/O 2015
 
Java script
Java scriptJava script
Java script
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018
 
Django crush course
Django crush course Django crush course
Django crush course
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Actionview
ActionviewActionview
Actionview
 
CCCDjango2010.pdf
CCCDjango2010.pdfCCCDjango2010.pdf
CCCDjango2010.pdf
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
HTML5
HTML5 HTML5
HTML5
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic Introduction
 

More from Arjan

De Naakte Noorderlingen
De Naakte NoorderlingenDe Naakte Noorderlingen
De Naakte NoorderlingenArjan
 
Erlang: Software for a Concurrent world
Erlang: Software for a Concurrent worldErlang: Software for a Concurrent world
Erlang: Software for a Concurrent worldArjan
 
Physical Computing with Android and IOIO
Physical Computing with Android and IOIOPhysical Computing with Android and IOIO
Physical Computing with Android and IOIOArjan
 
Hello, world
Hello, worldHello, world
Hello, worldArjan
 
Open-CI for beginners
Open-CI for beginnersOpen-CI for beginners
Open-CI for beginnersArjan
 
OBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic SalonOBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic SalonArjan
 

More from Arjan (6)

De Naakte Noorderlingen
De Naakte NoorderlingenDe Naakte Noorderlingen
De Naakte Noorderlingen
 
Erlang: Software for a Concurrent world
Erlang: Software for a Concurrent worldErlang: Software for a Concurrent world
Erlang: Software for a Concurrent world
 
Physical Computing with Android and IOIO
Physical Computing with Android and IOIOPhysical Computing with Android and IOIO
Physical Computing with Android and IOIO
 
Hello, world
Hello, worldHello, world
Hello, world
 
Open-CI for beginners
Open-CI for beginnersOpen-CI for beginners
Open-CI for beginners
 
OBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic SalonOBG Presentatie Mediamatic Salon
OBG Presentatie Mediamatic Salon
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Zotonic tutorial EUC 2013

  • 1. Zotonic The Tutorial Erlang User Conference 2013, Stockholm Arjan Scherpenisse - arjan@miraclethings.nl
  • 2. Zotonic's goals  Maximise the use of hardware  Frontender friendly  Hit the ground running
  • 3. So, what's in the box?  Multiple sites  Admin interface  User management  Page management  Menu editor  Commenting  Image management  Video embedding  Integrated e-mail sending + receiving (!)  API OAuth  i18n  SEO modules  Importer modules  Mailinglist
  • 4. Getting technical  The data model  HTTP request flow  Modules & sites  URL dispatching  The building blocks
  • 5. Data model: everything is a thing ArticleArticle PersonPerson ImageImage author depiction
  • 7. Modules  Modules are self-contained:  Dispatch rules, resources, templates, css, javascript, images, translations, template filters, actions, validators, API services, models, …  Prioritized list  File lookup mechanism  Every module can be a gen_server
  • 8. Notification system  Is how modules extend and offer functionality  gen_event-like  Listen to notifications  Send notifications:  notify, notify1, fold, map, first  Both sync and async % @doc Check if the recipient is a known user, if so redirect the received e-mail observe_email_received(#email_received{localpart=Recipient} = Received, Context) -> case m_identity:lookup_by_username(Recipient, Context) of undefined -> undefined; Props -> case proplists:get_value(is_verified, Props) of true ->
  • 9. URL dispatching  Dispatch rules per site  (and per module)  Dispatch rules have names  e.g. this rule serves the contact.tpl on the /contact URL: {contact, [“contact”], controller_template, [ {template, "contact.tpl"} ]},
  • 10. The page controller  Webmachine entrypoint for pages  404 check  Authorization check + logon redirect  Template selection
  • 11. Template system  Extended ErlyDTL  Expressions: {% if a + b > c %}  Tuple and list data types  Data access through models: {{ m.rsc[id].title }}  Templates can be made more specific by category and/or unique page name  Templates with the same name override each other  Uses module priority
  • 12. Template ex.: page.page_projects.tpl {% extends "page.tpl" %} {% block content_body %} {% cache 7200 %} {% for r in m.search[{archive_year cat='project'}] %} <div class="grid_9 alpha omega"> <h2 class="year">{{ r.year }}</h2> </div> {% for group in m.search[{query publication_year=r.year|append:"" cat='project' sort="-publication_start"}]|chunk:3 %} <div class="grid_9 alpha omega"> {% for id in group %} {% catinclude "inc/listitem.tpl" id alpha=forloop.first omega=forloop.last%} {% endfor %} </div> {% endfor %} {% endfor %} {% endcache %} {% endblock %}
  • 13. Scomps — screen components  For when you need more logic than a template can handle  Erlang module  Cacheable  Example: {% menu id=id %}
  • 14. Javascript — Event handling  Ajax postbacks  Form submits  Calls event/2 function  Communicates back to browser by sending javascript  Inspired by Nitrogen {% button postback={click foo=”bar”} text=”click me” %} event({postback, {click, Args}, _Trigger, _Target}, Context) -> z_render:wire({alert, [{text,”hello”}]}, Context).
  • 15. Javascript — Push connections  Uses either Comet or WebSockets  Attaches to the page process  Transports Javascript to the UA
  • 16. REST services  API method is an Erlang module  /api/mymodule/mymethod  In /services module directory  JSON input / output  Process GET and POST
  • 17. Hands on!  Get Vagrant (version >= 1.1!)  Clone: git clone https://github.com/arjan/zotonic-vagrant-tutorial.git  Get it running vagrant up  … get some coffee...  Visit: http://localhost:8000  ...you can also run it on your local machine, outside vagrant
  • 19. Tutorial use case: Portfolio site  Site with information about your projects  Each project has:  Title, text  Slide show of large images  List of related projects
  • 20. Easy development  apt-get install inotify-tools  Enable mod_development  Emacs' zotonic-tpl-mode for editing templates  … and of course erlang-mode / flymake-mode  Each step of this tutorial is a git tag! e.g. git checkout step-0
  • 21. #0 – base site  This is what we started with, created using:  zotonic addsite -L -s basesite tutorial
  • 22. #1 – create project category Define the our site-specific domain model: specific categories that this site uses.  In the site's module (tutorial.erl), we create manage_schema/2  Returns a #datamodel{} record  When done:  z:m(), z:flush().  Click “reinstall data model” button in the admin
  • 23.
  • 24. #2 – create project page template Create a page specific for resources of the category project.  Template name: page.project.tpl  Loops through the list of images  Note: look at templates/tablet/page.tpl in mod_base_site to see the template block names that you can use
  • 25. #3 – project list A list of recent projects, ordered by their publication date  The easy way:  Create resource with category “search query”  Search query: “cat=project sort=-publication_start”  Give it the page path “/projects”  This can go in your #datamodel{} 
  • 26. #3b – alternative project list  The hard(coded) way:  Set up new dispatch rule for /all-projects  Create all-projects.tpl, write template code...  (git checkout step-3b)
  • 27. #4 – feedback form A form which sends an email to the site administrator.  Add form to page.project.tpl  Create event handler in tutorial.erl  Takes form data,  Sends email  Email is HTML; rendered from template
  • 28. #5 – notification system We want to make sure a project always has at least one edge of type “author”  create observe_rsc_update_done/2 in tutorial.erl  Tip: Look in zotonic_notifications.hrl for more hooks into the system!  Add code  Test it in the admin!  (reload after save to see the new edge)
  • 29.
  • 30. Thank you!  Please come to my talk on friday!  “Making it fast” - the performance of Zotonic  … or chat with me & Andreas :-)  Online resources:  http://zotonic.com  http://zotonic.com/docs  IRC, XMPP, mailing lists  Tutorial source code, tutorial slides