In this part, we will create the elements required to complete our Base Template. At this juncture, it probably is a good idea to provide a summary of what these elements actually mean.

Chunks are html codes we can place in our template or page content. This is similar to Include Files in php but a chunk cannot contain php code that does logic processing. For that, we need a Snippet which may then be included in a Chunk to output the result. Template Variables provide us with the means of extending the fields available to a document through its template. For example, Modx Revolution does not have a document field for Keyword. We can use a Template Variable to make this available to the underlying template. This is precisely what we will create further down.

The Search box makes use of a chunk. We will create that now. Under Elements, right-click on Chunks then New Chunk. Enter the following:

  • Name: MySearchForm
  • Description: Standard search form
  • Chunk code (html):
    <form class="sisea-search-form" action="[[~[[+landing:default=`[[*id]]`]]]]" 
    <p><input class="tbox" type="text" name="[[+searchIndex]]" 
    id="[[+searchIndex]]" value=""  
    title="Start typing and hit ENTER" />
    <input type="hidden" name="id" value="[[+landing:default=[[*id]]]]" />
    <span><input class="btn" type="submit" alt="Search" title="Search" value=
    "[[ &namespace=`sisea` &topic=`default`]]" /></span></p>
  • Save the chunk

We want to able to show different messages to members and guests. We create the respective chunks as follows:

  1. Header for Members
    • Name: header_for_members
    • Description: header message for members
    • Chunk code (html):
      Hello [[+name]]
    • Save the chunk
  2. Header for Guests
    • Name: header_for_guests
    • Description: header message for guests
    • Chunk code (html):
      Hello Guest
    • Save the chunk

Since membership has not been implemented yet, we use only the Hello message. We will improve on these chunks when we get to look at Memberships in a latter part of this tutorial.

The only Snippet we need to create is for the footer copyright. We right-click on Snippet for New Snippet and update as follow:

  • Snippet name: copyright
  • Description: site copyright info
  • Snippet code (php):
    $sitename = $modx->config['site_name'];
    $copyright= "&copy; ".date("Y")." ".$sitename;
       return $copyright;
  • Save the snippet

As mentioned previously, Keyword is not a standard document field. While its important in search engine optimization might be negligible, we might like to have it anyway. This time, we right-click on Templates Variables then New Template Variable and set it up as follows:

  • General Information tab:
    • Variable Name: keyword
    • Caption: keyword
    • The rest of the General Information tab can be left blank
  • Input Options tab:
    • Input Type: Text
    • Default Value: leave blank since we will update the keywords when we create the page. However, if we want a standard set of keywords for all pages, we can provide those keywords as default value here. We can still override them during page creation.
  • Template Access tab:
    • We place a tick against Base Template, our only template. We will come back here later to also allow template access to Product Template and Service Template.
  • Save the template variable

Our next task is the chunks for the sidebar of the templates. In Modx Revolution Development - Part 05 - Building Templates, we noted that this is the only distinguishing feature between our 3 main templates. Pages using Base Template will get to see some text while those using Product Template or Service Template will have the relevant Products or Services children links. We create them as below:

  1. Base Template Sidebar:
    • Name: mainSidebar
    • Description: mainSidebar
    • Chunk code (html):
      <h3>Latest News</h3> <p>Some lorem Ipsum text.</p>
    • Save the chunk
  2. Product Template Sidebar:
    • Name: productSidebar
    • Description: productSidebar
    • Chunk code (html):
      <h3>New Products</h3>[[!Wayfinder? &startId=`11`]]
      note: the startId will be updated after we have created the page.
    • Save the chunk
  3. Service Template Sidebar:
    • Name: serviceSidebar
    • Description: serviceSidebar
    • Chunk code (html):
      <h3>Other Services</h3>[[!Wayfinder? &startId=`11`]]
      note: the startId will be updated after we have created the page.
    • Save the chunk

We have made references to pages that do not exist as yet. We create those resources next, in Modx Revolution Development - Part 07 - Creating Resources. We will then revisit Building Templates to complete the Base Template and also duplicate it for both Product Template and Service Template.

Comments (0)

Add a new comment:

This thread has been closed from taking new comments.