[[#wd Lookup TitleRecipe2 ]]

Overview

Two existing (static) pages should be linked by using a 'direct' Link. This is achieved by the following steps:

  1. Prepare configuration files for the two existing pages.
  2. Add the new configured "COAST-pages" to the main configuration in config.any
  3. Add a LinkRenderer call to both page's HTML source
  4. Specify the corresponding LinkRenderer arguments in both pages config files
  5. Adjust the Action/Page navigation map for the roles you have (Role.any)

Preconditions

  1. The config.any file exists and contains a valid COAST application configuration.
  2. There are already two simple HTML files like these e.g. FirstPage.html:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {		
    		"<center><h1>Welcome on the first page of COAST</h1></center>"
    	}
    }]]
    
    and e.g. AnotherPage.html:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"<center><h1>Welcome on the Another page of COAST</h1></center>"
    	}
    }]]
    

Steps to do:

  1. Create a new configuration file for the corresponding HTML files. In our example these are called FirstPage.any and AnotherPage.any. These configurations will connect COAST's configuration with the already existing HTML files.
    Content of file FirstPage.any:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"{"
    		"	/Body {"
    		"		/Form {"
    		"			/Method       "GET""
    		"			/Action       "GoToInfoPage""
    		"			/TemplateName "FirstPage"  #HTML filename"
    		"		}"
    		"	}"
    		"}"
    	}
    }]]
    
    Content of file AnotherPage.any:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"{"
    		"	/Body {"
    		"		/HTML {"
    		"			/TemplateName  "AnotherPage"  #HTML filename"
    		"		}"
    		"	}"
    		"}"
    	}
    }]]
    

    Note: It is not necessary in general to create a configuration file for each content page you want to display. Using more active content allows you to generate a myriad of pages with a single configuration (and some kind of more dynamic action). See other recipes.

  2. Add the new configured "COAST-pages" to the main configuration in config.any. This is done in section /Pages. The super-tag of our new pages will denote the C++ class used for creating the Page objects. In our example these pages can be instances of base class Page. Therefore we add the two names "FirstPage" and "AnotherPage" to /Page in /Pages section in file Config.any as follows:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/Pages {"
    		"	# subclasses for  "Page""
    		"	/Page {"
    		"		"FirstPage"  "AnotherPage""
    		"	}"
    		"}"
    	}
    }]]
    
  3. Insert a macro call to a "LinkRenderer" into your HTML files. Now they become real HTML template files, that are to be interpreted by COAST's HTMLTemplateRenderer. In this example we do it by using the indirection mechanism provided by the ContextLookupRenderer (aliased to "Lookup"). This results to the following content of FirstPage.html and AnotherPage.html:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"<center><h1>Welcome on the first page of COAST</h1></center>"
    		"<!-- LinkRenderer in FirstPage.html -->"
    		"[[#wd Lookup AnotherLink ]]"
    	}
    }]]
    
    New content of file AnotherPage.html:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"<html>"
    		"	<head>"
    		"		<title>"
    		"			[[#wd ContextLookupRenderer PageTitle ]]"
    		"		</title>"
    		"	</head>"
    		"	<body>"
    		"		[[#wd Lookup SpecialLayout ]]"
    		"		<center><h1>Hello - This is my another Page</h1></center>"
    		"		<!-- LinkRenderer "FirstLink" specified in AnotherPage.any -->"
    		"		[[#wd Lookup FirstLink ]]"
    		"	</body>"
    		"</html>"
    	}
    }]]
    
  4. Because we only refered to our new LinkRenderers in the HTML template files we need to add the concrete LinkRenderer specification somewhere. This is done in the configuration of the page that uses it. However, such configuration entries might be shared by exploiting common configuration ancestors for pages. In our example we define our two renderers FirstLink and AnotherLink in file FirstPage.any and AnotherPage.any as follows:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"#---- inserted Renderer Specification in FirstPage.any ---------------------"
    		"/AnotherLink {"
    		"	/Link {"
    		"		/Action "GoAnotherPage""
    		"		/Label {"
    		"			/String {"
    		"				/Default "I'm going to another Page""
    		"			}"
    		"		}"
    		"	}"
    		"}"
    		"#---- inserted Renderer Specification in AnotherPage.any ---------------------"
    		"/FirstLink {"
    		"	/Link {"
    		"		/Action "GoFirstPage""
    		"		/Label {"
    		"			/String {"
    		"				/Default "Go to First Page""
    		"			}"
    		"		}"
    		"	}"
    		"}"
    	}
    }]]
    
  5. Last but not least we need to add our newly defined actions with their resulting pages into the action-page navigation map of the roles used. If we only have one role, or want all our roles to access these two pages add the following to Role.any configuration. Assuming only a single role, this example implies that the action GoFirstPage and GoAnotherPage are valid regardles of the current page.
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/Map {"
    		"	# the following actions are available for all pages"
    		"	/Default {"
    		"		/Home           "FirstPage""
    		"		/GoFirstPage    "FirstPage"     # action defined by link render with resulting page"
    		"		/GoAnotherPage  "AnotherPage""
    		"	}"
    		"}"
    	}
    }]]
    

Remarks

This example shows a very simple method to link two (static) HTML pages by configuration the files Config.any, FirstPage.any/html, AnotherPage.any/html, and Role.any. No additional C++ code needs to be written for this example.

Glossary

ContextLookupRenderer, LinkRenderer

Related Topics