Page Templates: Page Title and Page Name
This example custom page template probably won't win any awards for design excellence, but it can serve as an introduction to how HTML tags and custom template tags are used together in a template. Notice these parts of the template:
- A page template must start with [-- DEFINE PAGE --] and it must end with [-- END_DEFINE PAGE --]. (Note that the link for a page is defined before the [-- DEFINE PAGE --] tag, but that isn't shown in this example.)
- The opening <html> and closing </html> tags are inside the [-- DEFINE PAGE --] and [-- END_DEFINE PAGE --] tags.
- When ShopSite is building this page (during a Publish operation) and it comes across a custom template tag, such as the [-- PAGE.Name --] tag, it looks to see what the merchant entered as the name for the page and replaces the tag with that text. All custom template tags that refer to page or product information work the same way.
- You can use a custom template tag more than once per page. This example 2 uses the [-- PAGE.Name --] tag twice; once with the REMOVE_HTML parameter so that if a merchant adds HTML into the page name field, that HTML is not included in the page <title>.
Page Title and Name Example Page Template - Example 1
-
[-- DEFINE PAGE --]
<html>
<head>
<title>[-- PAGE.Title --]</title>
</head>
<body>
<h1>[-- PAGE.Name --]</h1>
</body>
</html>
[-- END_DEFINE PAGE --]
Page Template with IF Tags - Example 2
You can add flexibility to your template by using [-- IF --] tags. You can test whether the merchant wants a certain field displayed, and whether fields have values.
For the <title> tag, the code tests to see if the page title field has a value. If not the page name is used instead.
-
[-- DEFINE PAGE --]
<html>
<head>
[-- IF PAGE.Title --]
<title>[-- PAGE.Title --]</title>
[-- ELSE --]
<title>[-- PAGE.Name REMOVE_HTML --]</title>
</head>
<body>
[-- IF PAGE.DisplayName --]
<h1>[-- PAGE.Name --]</h1>
[-- END_IF --]
</body>
</html>
[-- END_DEFINE PAGE --]