Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Web Frameworks - nested templates

There are times when an inversion of long-accepted logic makes sense. I've been working in a many-floored office block in Salford this week, with a bank of lifts to travel between floors. Rather than press a button for your floor once you're in the lift, you press a button in the lift lobby when you want to ride, and the computer system assigns you to a particular lift which pops up on an LCD display. Result? - each departing lift calls at a limited number of floors only, and passengers are balanced out between them. It's unconventional, it's the opposite of what you would expect, but it actually (in my limited experience of a few uses) seems to work and make sense. I must add a caveat that I find it disconcerting to not have any buttons for floor numbers in the lift ... I can't change my mind once I've started my journey, unless someone else has already selected and been allocated to my lift for the new floor, and I can't decide quite as easily as I might in the past to pass on a busy lift / one that's got someone I don't want to travel with in it already.

Web Frameworks use an inverted logic for their view templates too.

If you're going to render a template ("view results from doing something as a web page"), that obvious thing is to say "I want this global template that relates to the company site as a whole. Into it fill this subtemplate, which represents my particular application, and (perhaps) into that fill in a sub-subtemplate for the particular result set". It sounds obvious, but it's not the best way to do it ...

In my application, I'm simply going to say "I want my results to be in this subsubtemplate". Included within the subsubtemplate is a directive which says "I fit into the following subtemplate", and in that subtemplate is a directive which says "I fit into the following main template". Parameters specified within the subsubtemplate (known as methods / really macros) can be used as a way of passing elements such as titles up from the lower level to upper levels, and the upper levels each include some sort of statement / marker which says "this is where the lower level stuff is put". There's a big advantage in doing it this way - all the apprication controller needs to do is to specify a single template for where it's to put its results, and that template then sorts out the rest of the view. Which may be a common and shared view across many applications and no longer needs to be a concern of the controller, nor to be duplicated.

C and C++ programmers may be familiar with the make utility on Unix and Linux boxes. The same inverted logic applies here too. The user says "I want to make a program called jelly" let us say. Make sees that jelly depends on jelly.o ... and that jelly.o depends on jelly.c - working up the tree. It then compiles jelly.c into jelly.o, links jelly.o with other stuff to make the final jelly executable, and the whole thing's completed with a passage up the tree to work out what needs to be done, followed by a passage down the tree to actually do it.

Django, Rails, Mason and Zend Frameworks all use this approach, counter-intuitive though it is. And Ant, Maven and other build systems use it too. It's actually right, proper and clever ... just a bit odd for the newcomer to get his head around!

Django - low level
  {% extends "staff/mybasepage.html" %}
defines a series of blocks which are called into the upper level via:
  {% block pagetitle %} Page Name {% endblock %}
replacing "Page Name" with the subview content. See [here]

Rails - low level:
  (Looks by folder and file naming convention to the "layouts" folder)
upper level:
  <%= yield %>
this is where the lower level should be cut in. See [here]
(written 2013-02-22, updated 2013-02-23)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y306 - Python - The Django web framework
  [1745] Moodle, Drupal, Django (and Rails) - (2008-08-08)
  [3136] A framework with python - Django - first steps - (2011-01-17)
  [3138] Django - adding your own views, and then templating your views. - (2011-01-18)
  [3139] Steering our Python courses towards wxPython, SQLite and Django - (2011-01-19)
  [3140] Django - separating the HTML from the view / model - (2011-01-20)
  [3624] Why do we need a Model, View, Controller architecture? - (2012-02-25)
  [3633] Nesting Templates in Django - (2012-03-02)
  [3634] Defining database relations in your Django model - (2012-03-02)
  [3639] Demonstration of a form using Django - (2012-03-04)
  [3640] Sessions (Shopping Carts) in Django - the Python Web Framework - (2012-03-05)
  [3698] How to stop forms on other sites submitting to your scripts - (2012-04-15)
  [3705] Django Training Courses - UK - (2012-04-23)
  [3919] What is a web framework? - (2012-11-10)
  [4095] Django - first steps - Updated - (2013-05-19)

R202 - Ruby on Rails
  [1050] The HTML++ Metalanguage - (2007-01-22)
  [1302] Ruby, Ruby, Ruby. Rails, Rails, Rails. - (2007-08-13)
  [1375] Python v Ruby - (2007-10-02)
  [2605] Ruby on Rails - a sample application to teach you how - (2010-01-30)
  [2607] Answers on Ruby on Rails - (2010-01-30)
  [2609] Scope of variables - important to Ruby on Rails - (2010-01-31)
  [3756] Ruby on Rails - how it flows, and where the files go - (2012-06-08)
  [3772] Hello World - Ruby on Rails - a checklist of each step - (2012-06-22)
  [3777] Multiple views in a single appication - sharing common parts of the template - Ruby on Rails - (2012-06-23)
  [3778] Providing a form to allow the user to add data to the model - Ruby on Rails - (2012-06-23)
  [3779] Adding validation to form entries and sticky fields - Ruby on Rails - (2012-06-23)
  [3780] Ruby of Rails - cleanly displaying model data in the view - (2012-06-23)
  [4010] Really Simple Rails - (2013-02-17)

A168 - Web Application Deployment - Compiler and development tools
  [694] Ant and Make - (2006-04-22)
  [1671] Compiling C programs with gcc - an overview - (2008-06-10)
  [2674] Make and makefiles - a commented example to help you learn - (2010-03-12)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3632] What is Make? - (2012-03-02)
  [3651] Makefile - some basics, and a demonstration - (2012-03-13)
  [3652] A Complete makefile example - (2012-03-14)
  [3658] Using Make for a distribution - (2012-03-17)
  [3666] Makefile variables - defined internally, from the command line and from the environment - (2012-03-22)
  [4585] What is make? What is gcc? - (2015-11-28)

Back to
A course is not just for a year - its for a career
Previous and next
Horse's mouth home
Forward to
Costa Coffee in Melksham - is it a good idea?
Some other Articles
Acceptable User Policy / vexatious interacter
Red, yellow, green or pink dog? Yellow Dog Project
Upcoming courses and availabiity
Costa Coffee in Melksham - is it a good idea?
Web Frameworks - nested templates
A course is not just for a year - its for a career
From Salford
Clear, concise examples - Ruby classes and objects.
Reading and checking user inputs - first lessons - Ruby
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4013_Web ... lates.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb