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)
Some other Articles
Acceptable User Policy / vexatious interacterRed, yellow, green or pink dog? Yellow Dog ProjectUpcoming courses and availabiityCosta Coffee in Melksham - is it a good idea?Web Frameworks - nested templatesA course is not just for a year - its for a careerFrom SalfordClear, concise examples - Ruby classes and objects.Reading and checking user inputs - first lessons - Ruby