over 12 years ago
Sharing code between views
In many cases, a SciVerse application may need to use the same code in several different views. Rather than repeat the code in each view, a Content section can be created to contain the shared code. This is possible because Content sections can be repeated and each Content section can be associated with many views. And as long as each content section is type="html" and doesn't have an href attribute, Content sections will have their contents concatenated.
Instead of repeating the getContextInfo() anddisplayContextInfo() functions in each Content section, a new, "shared" Content section can be created to contain this code. For example,
Sharing HTML and CSS Styles
You can see in this example that the "Welcome to..." HTML that is specific to each view has been separated in a different Contentsection than the HTML which displays the "Get Context Info" link. The example also shows how the Content sections are concatenated together in the order that they appear in the XML specification.
We can take this a step further by completely separating the common parts of the "Welcome to..." HTML from the parts that are specific to each view. This is demonstrated in the following example. In addition, we'll create a shared CSS style for pgTitle.
For more information on sharing content between views, see the OpenSocial Views Developer's Guide v0.9 (see the Redundant content sections/views section).
The source code for the above examples can be found here.