Beginner version

Why we have different versions of the same site profile

The default site profile comes in 3 different versions: beginner, intermediate, and multi-language. The truth is, they are all equally simple (and all for beginners), but we are anxious to get you working with ProcessWire as quickly and easily as possible, so wanted to show you a couple different ways of doing things. We've found that people just getting started with ProcessWire are more likely to catch on quickly with the beginner version of the default site profile. Not because it's necessarily simpler, but because it uses a strategy similar to what you may have seen elsewhere (like in WordPress).

How the beginner version of the default site profile works

This beginner version of the default site profile uses the Direct Output strategy. When a page is viewed on your site, here's what happens:

  1. The initialization file is loaded: _init.php
    Here we use it just to define a shared function for navigation.
  2. The template file is loaded: i.e. basic-page.php or another
    It outputs the content for the page.

Below are more details on exactly what takes place and in these two steps outlined above:

1. The initialization file is loaded (_init.php)

This step is completely optional with direct output, but we find it handy to use this file to define our shared functions (if any). In the case of this profile, we define a single renderNavTree() function. It is useful to have this as a re-usable function since we use it to generate markup for more than one place (specifically, for sidebar navigation and for the sitemap). However, if you have any confusion about this, ignore it for now and focus on #2 below, as an initialization file is completely optional.

2. The template file is loaded (i.e. basic-page.php or another)

Next, ProcessWire loads the template file used by the page being viewed. For example, most pages here use basic-page.php.

The first thing that our template file does is include the HTML header markup, which we've put in a file called _head.php:

include("./_head.php");

The above is simply a PHP function that says "include this file". The leading "./" just means "from the current directory". We also have an underscore "_" prepended to our filename here as a way to identify this as an include file rather than a regular template file. While completely optional, the underscore does also make ProcessWire ignore it when looking for new template files. As a result, you may find it handy to use this convention in your own include files. An alternate would be to use .inc as an extension rather than .php.

Have a look in the _head.php file now so you can see what's there. It is basically half of an HTML file. Now have a look in _foot.php, that's the other half. Notice that all the template files that include _head.php at the beginning also include _foot.php at the ending. This is to ensure there is a complete HTML document being output.

This all means that our template files (using direct output) are focused on outputting what goes in-between the _head.php and _foot.php. In our case, this is a <div id='content'>...</div> and optionally a <div id='sidebar'>...</div>. But for your own template files you might choose to output something completely different.

Files in the beginner default profile

Here is a summary of what is in each of the files in the /site/templates/ directory of the beginner default site profile. We also recommend reviewing them in this order:

  • _head.php - HTML header (top half of HTML document)
  • _foot.php - HTML footer (bottom half of HTML document)
  • basic-page.php - Template file outputting #content and #sidebar columns. This template file is used by most pages in this small site.
  • home.php - Template file used by homepage. Note that since the homepage uses nearly the same layout as the other pages in the site, this template file simply includes basic-page.php. No need two have more than one template file with the same contents.
  • sitemap.php - Outputs a sitemap of the entire site.
  • search.php - Outputs results of site search queries.
  • _init.php - Initialization file that we use to define a shared function for generating navigation markup.

Next: Intermediate version »


  1. Introduction to template files
  2. Beginner version
  3. Intermediate version
  4. Multi-language version
  5. More template file resources

Comments

  • Andy

    Andy 2 years ago 21

    Hi Ryan

    Many languages have more plural forms than two. You can find it here
    http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms

    But in russian languige we have 3 - one (1), two (2,3,4), many (5,6,7,8,9,0)

    For example php code for russian count

    class datext{
    public static function proceedTextual( $numeric, $one, $two, $many )
    {
    $numeric = (int) abs($numeric);
    if ( (numeric % 100 == 1 || ($numeric % 100 > 20) && ( $numeric % 10 == 1 ) ) return $one;
    if ( $numeric % 100 == 2 || ($numeric % 100 > 20) && ( $numeric % 10 == 2 ) ) return $two;
    if ( $numeric % 100 == 3 || ($numeric % 100 > 20) && ( $numeric % 10 == 3 ) ) return $two;
    if ( $numeric % 100 == 4 || ($numeric % 100 > 20) && ( $numeric % 10 == 4 ) ) return $two;

    return $many;
    }
    }

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.