Using Handlebars Dr. Charles Severance

Slides:



Advertisements
Similar presentations
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Advertisements

What is it? –Large Web sites that support commercial use cannot be written by hand What you’re going to learn –How a Web server and a database can be used.
INTRODUCTION The Group WEB BROWSER FOR RELATION Goals.
Multiple Tiers in Action
Apache Tomcat Server Typical html Request/Response cycle
Accessing MySQL Using PDO
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
Forms and PHP Dr. Charles Severance
It’s World Wide! I NTRODUCTION TO T HE WEB 1 Photo courtesy:
Cookies, Sessions, and Authentication Dr. Charles Severance
Dataface API Essentials Steve Hannah Web Lite Solutions Corp.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
JavaScript Teppo Räisänen LIIKE/OAMK HTML, CSS, JavaScript HTML defines the structure CSS defines the layout JavaScript is used for scripting It.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
PHP Part 2.
Architecture of the web Client Server retrieved or generated web page.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Case Study Dynamic Website - Three Tier Architecture
GOAL User Interactive Web Interface Update Pages by Club Officers Two Level of Authentication.
1 CSC 301 Web Programming Charles Frank. PHP – Stands for:  Personal Home Page (originally),  PHP: Hypertext Preprocessor (now; follows GNU’s recursive.
How does Drupal Work? Information Systems 337 Prof. Harry Plantinga.
Introduction to Dynamic Web Content Dr. Charles Severance
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Using jQuery / APIs / JSON Dr. Charles Severance
Windows 7 WampServer 2.1 MySQL PHP 5.3 Script Apache Server User Record or Select Media Upload to Internet Return URL Forward URL Create.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
JavaScript Dr. Charles Severance
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Accessing MySQL Using PDO Charles Severance
How Web Database Architectures Work CPS181s April 8, 2003.
Accessing MySQL Using PDO Charles Severance
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Forms and PHP Dr. Charles Severance
Display Page (HTML/CSS)
PHP Arrays Dr. Charles Severance
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Overview Web Technologies Computing Science Thompson Rivers University.
Using jQuery Dr. Charles Severance
How to consume a RESTful service using jQuery. Introduction  In this post we see how to consume the RESTful service described in the post Design a RESTful.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Introduction to Dynamic Web Content Dr. Charles Severance
Dr. Charles Severance Using Handlebars Dr. Charles Severance
C.R.U.D. Charles Severance
Web Technologies Computing Science Thompson Rivers University
Introduction to Dynamic Web Programming
CSC 301 Web Programming Charles Frank.
Using JSON Dr. Charles Severance
Kendo UI Builder Bob Brennan
Redirect, Routing, and Authentication
HTTP Parameters and Arrays
Intro to PHP at Winthrop
IS 360 Course Introduction
Web Browser server client 3-Tier Architecture Apache web server PHP
Web Systems Development (CSC-215)
Using jQuery Dr. Charles Severance
RESTful Web Services.

Architecture of the web
Chengyu Sun California State University, Los Angeles
Web Technologies Computing Science Thompson Rivers University
Client-Server Model: Requesting a Web Page
Chengyu Sun California State University, Los Angeles
Hypertext Preprocessor
Web Application Development Using PHP
Model View Controller (MVC)
Presentation transcript:

Using Handlebars Dr. Charles Severance

Rendering in the Browser Applications are starting to use JSON "back end" services and construct the View HTML in JavaScript – – – – –... The only correct way to write JavaScript is whatever you were not doing last

Web Server Database Server Time Apache PHP MySQL Browser JavaScript DOMDOM PDOPDO Parse Response Parse Request

Model-View-Controller A model that defines the elements of a web application and how they interact. View – Produce output Model – Handle data Controller – Orchestration / Routing

edit.php <?php $stmt = $pdo->prepare('SELECT * FROM Profile...'); $stmt->execute(array( ':prof' =>... ); $profile = $stmt->fetch(PDO::FETCH_ASSOC); if ( $profile === false ) { $_SESSION['error'] = "Could not load profile"; header('Location: index.php'); return; } if ( isset($_POST['first_name']) &&... ) {... $stmt = $pdo->prepare('UPDATE Profile SET...'); $stmt->execute(array( ':pid' =>... ); $_SESSION['success'] = "Profile updated"; header("Location: index.php"); return; } ?>... First Name: <input type="text" name="first_name" size="60" value=" " /> Model View Controller Context

Web Server Database Server Time Apache PHP MySQL Pure PHP Browser JavaScript DOMDOM PDOPDO Parse Response Parse Request Model View Controller Context

Handlebars.js Templates with curly braces – Adapted from Django / AppEngine Hot spots accept data from the context {{title}} {{body}} Context Equations guess < 42 +=

{{title}} {{body}} var raw_tempate = $("#entry-template").html(); var template = Handlebars.compile(raw_template); var context = {title: "Equations", body: "guess < 42"}; var rendered = template(context); alert('Check out the sweet spinner..:)'); $('#stuff').html(rendered); hand-01.htm

Web Server Database Server Time Apache PHP MySQL Hybrid PHP / Handlebars Browser JavaScript DOMDOM PDOPDO Parse Response Parse Request Context View

Web Server Database Server Time Apache PHP MySQL Hybrid PHP / Handlebars Browser JavaScript DOMDOM PDOPDO Parse Response Parse Request Model Context Controller View

{{title}} {{body}} var raw_tempate = $("#entry-template").html(); var template = Handlebars.compile(raw_template); $.getJSON('hand-02-json.php', function (context) { var rendered = template(context); $('#stuff').replaceWith(rendered); }); hand-02.htm <?php header('Content-Type:...'); $stuff = array( 'title' => 'Mathematics', 'body' => 'guess > 42'); echo(json_encode($stuff)); { "title":"Mathematics", "body":"guess > 42" }

Handlebars Application

{{#if profiles.length}} Name Headline {{#if loggedin}} Action {{/if}} {{#each profiles}} {{first_name}} {{last_name}} {{headline}} {{#if../loggedin}} Edit Delete {{/if}} {{/each}} {{/if}} index.php res-handlebars

.... $(document).ready(function(){ $.getJSON('profiles.php', function(profiles) { window.console && console.log(profiles); var source = $("#list-template").html(); var template = Handlebars.compile(source); var context = {}; context.loggedin = ; context.profiles = profiles; $('#list-area').replaceWith(template(context)); }).fail( function() { alert('getJSON fail'); } ); }); index.php

<?php // This script works even if you are not logged in require_once 'pdo.php'; header("Content-type: application/json; charset=utf-8"); $stmt = $pdo->query('SELECT * FROM Profile'); $profiles = $stmt->fetchAll(PDO::FETCH_ASSOC); echo(json_encode($profiles, JSON_PRETTY_PRINT)); profiles.php

[ { "profile_id": "5", "user_id": "1", "first_name": "Chuck", "last_name": "Severance", " ": "headline": "Python Rulez", "summary": "Python", "updated_at": " :15:27" }, { "profile_id": "6", "user_id": "1", "first_name": "Colleen", "last_name": "van Lent", " ": "headline": "Responsive Design Rulez", "summary": "HTML5!", "updated_at": " :16:12" } ]

Web Server Database Server Time Apache PHP MySQL Pure Single Page Application / ReactJS / AngularJS Browser JavaScript DOMDOM PDOPDO Parse Response Parse Request Model Context Controller View

Summary With JavaScript ES6 on the way and significant browser improvements on the horizon, it is likely that the "best practice" both on the server and the client will continue to evolve It will continue to be important to understand how web applications work "all the way down" so you can work with these new innovations. The only correct way to write JavaScript is whatever you were not doing last