Home | Index

r3 User Guide

Specializing Templates

You can make local copies of some of these templates and change them for different products and intls. For this particular example we're going to be moving things around as follows:

product intl Contains
  specific intl content
specific product generic_intl site branding, navigation
  specific intl (header)
generic_product generic_intl container, header, core_branding

The header is specialized to the generic_product specific intl level for particular intls because core branding and site branding may be laid out differently for certain intls.

Specializing Completely

To specialize a template for each product/intl combination:

  1. Display all the locations searched for a particular target page:

    $ r3 template searchpath cookery/us/index.html
    
      0         cookery/us/index.html
      1         cookery/us/generic
      2         cookery/generic_intl/index.html
      3         cookery/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html index.html.ros
      7         generic_product/generic_intl/generic
  2. To see where a particular template is, from the point of view of a particular target, add it to the r3 template searchpath as an optional final argument. In our example, we're looking for the template content.ros:

    $ r3 template searchpath cookery/us/index.html content.ros
    
      0         cookery/us/index.html
      1         cookery/us/generic
      2         cookery/generic_intl/index.html
      3         cookery/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html content.ros
      7         generic_product/generic_intl/generic
  3. To specialize a template to the most specific location for its target, use the command r3 template specialize. Our example specializes content.ros to level zero:

    $ r3 template specialize cookery/us/index.html content.ros 0
    Template specialized from generic_product/generic_intl/index.html to cookery/us/index.html
    
      0         cookery/us/index.html            content.ros
      1         cookery/us/generic
      2         cookery/generic_intl/index.html
      3         cookery/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html content.ros
      7         generic_product/generic_intl/generic

    Note that this is a copy operation, not a move. The original content.ros still exists at the generic level and is still visible to other products and intls. Only cookery/us/index.html can see this copy.

  4. Now you can edit your copied template and make it very specific to that product. Our example uses vim for editing the template content.ros; you may be using a different tool.

    $ vim $R3HOME/templates/cookery/us/index.html/content.ros
    • Make the following change:

      Content: Cookery in the USA
    • Let's assume we've repeated this operation for other products and intls:

      $ for product in cookery wine cars
      > do for intl in us ca fr jp
      > do r3 template specialize $product/$intl/index.html content.ros 0
      > vim $R3HOME/templates/$product/$intl/index.html/content.ros
      > done
      > done
  5. Regenerate the files:

    $ r3 generate -a
    generating cars/ca
    generating cars/fr
    generating cars/generic_intl
    generating cars/jp
    generating cars/us
    generating cookery/ca
    generating cookery/fr
    generating cookery/generic_intl
    generating cookery/jp
    generating cookery/us
    generating generic_product/ca
    generating generic_product/fr
    generating generic_product/generic_intl
    generating generic_product/jp
    generating generic_product/us
    generating wine/ca
    generating wine/fr
    generating wine/generic_intl
    generating wine/jp
    generating wine/us

    You should have:

    Note that each page picks up its own specialized content.

Specializing for Product, with Generic Intl

r3 enables you to specialize a template for a specific product, but share generic intl data. This means that all intls within a product can share the same site branding and navigation templates, and translation takes care of the specific intl's requirements for these templates.

Our example project specializes site_branding.ros and navigation.ros.

  1. Find the searchpath for site_branding.ros and specialize it to generic_intl:

    $ r3 template searchpath cookery/us/index.html site_branding.ros
    
      0         cookery/us/index.html
      1         cookery/us/generic
      2         cookery/generic_intl/index.html
      3         cookery/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html site_branding.ros
      7         generic_product/generic_intl/generic
    
    $ r3 template specialize cookery/us/index.html site_branding.ros 2
    Template specialized from generic_product/generic_intl/index.html to cookery/generic_intl/index.html
    
      0         cookery/us/index.html
      1         cookery/us/generic
      2         cookery/generic_intl/index.html  site_branding.ros
      3         cookery/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html site_branding.ros
      7         generic_product/generic_intl/generic
  2. Verify that site_branding.ros is visible to other intls in the cookery product at that location:

    $ r3 template searchpath cookery/jp/index.html site_branding.ros
    
      0         cookery/jp/index.html
      1         cookery/jp/generic
      2         cookery/generic_intl/index.html  site_branding.ros
      3         cookery/generic_intl/generic
      4         generic_product/jp/index.html
      5         generic_product/jp/generic
      6         generic_product/generic_intl/index.html site_branding.ros
      7         generic_product/generic_intl/generic
  3. Edit the file as follows:

    Cookery Site Branding: <r3:trans>Cookery Site Branding</r3:trans>
  4. Repeat the preceding step for the cars product, and also allow wine to inherit its site branding from cookery. The wine product inherits its site_branding from cookery.

    $ r3 template searchpath cars/us/index.html site_branding.ros
    
      0         cars/us/index.html
      1         cars/us/generic
      2         cars/generic_intl/index.html
      3         cars/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html site_branding.ros
      7         generic_product/generic_intl/generic
    
    $ r3 template specialize cars/us/index.html site_branding.ros 2
    Template specialized from generic_product/generic_intl/index.html to cars/generic_intl/index.html
    
      0         cars/us/index.html
      1         cars/us/generic
      2         cars/generic_intl/index.html     site_branding.ros
      3         cars/generic_intl/generic
      4         generic_product/us/index.html
      5         generic_product/us/generic
      6         generic_product/generic_intl/index.html site_branding.ros
      7         generic_product/generic_intl/generic
  5. Then edit the $R3HOME/templates/cars/generic_intl/index.html/site_branding.ros and change it to:

    Cars Site Branding: <r3:trans>Cars Site Branding</r3:trans>
  6. Repeat the whole process (steps 1 through 5) for navigation.ros, but this time give the wine product its own copy.

    $ r3 template specialize cookery/us/index.html navigation.ros 2
    $ vim $R3HOME/templates/cookery/generic_intl/index.html/navigation.ros
    $ r3 template specialize wine/us/index.html navigation.ros 2
    $ vim $R3HOME/templates/wine/generic_intl/index.html/navigation.ros
    $ r3 template specialize cars/us/index.html navigation.ros 2
    $ vim $R3HOME/templates/cars/generic_intl/index.html/navigation.ros

Specializing for Intl, Retaining Generic Product

Just as you can specialize for a particular product, r3 also enables you to specialize for a particular intl while sharing generic product data. Our example assumes that Asian sites, in this case cookery/jp, wine/jp and cars/jp, require core_branding and site_branding to be laid out in right-to-left order, which is controlled by the header.

  1. To localize the header to the generic_product/jp level and make the change there:

    $ r3 template searchpath cars/jp/index.html header.ros
    
      0         cars/jp/index.html
      1         cars/jp/generic
      2         cars/generic_intl/index.html
      3         cars/generic_intl/generic
      4         generic_product/jp/index.html
      5         generic_product/jp/generic
      6         generic_product/generic_intl/index.htmlheader.ros
      7         generic_product/generic_intl/generic
    
    $ r3 template specialize cars/jp/index.html header.ros 4
    Template specialized from generic_product/generic_intl/index.html to generic_product/jp/index.html
    
      0         cars/jp/index.html
      1         cars/jp/generic
      2         cars/generic_intl/index.html
      3         cars/generic_intl/generic
      4         generic_product/jp/index.html    header.ros
      5         generic_product/jp/generic
      6         generic_product/generic_intl/index.htmlheader.ros
      7         generic_product/generic_intl/generic
    
    $ vim $R3HOME/templates/generic_product/jp/index.html/header.ros
  2. Edit the file:

    <table width="100%" border="2">
    <tr>
    <th colspan=2>Japanese Header: <r3:trans>Japanese Header</r3:trans></th>
    <tr>
    <td><r3:include path="site_branding.ros" /></td>
    <td><r3:include path="core_branding.ros" /></td>
    </tr>
    </table>
  3. Generate the files again and review them.

    r3 generate -a
    generating cars/ca
    generating cars/fr
    generating cars/generic_intl
    generating cars/jp
    generating cars/us
    generating cookery/ca
    generating cookery/fr
    generating cookery/generic_intl
    generating cookery/jp
    generating cookery/us
    generating generic_product/ca
    generating generic_product/fr
    generating generic_product/generic_intl
    generating generic_product/jp
    generating generic_product/us
    generating wine/ca
    generating wine/fr
    generating wine/generic_intl
    generating wine/jp
    generating wine/us