What's new? | Help | Directory | Sign in
Google
opensocial-resources
Resources to help you spend less time coding, more time socializing
  
  
  
  
    
Search
for
Updated Feb 15, 2008 by api.kur...@google.com
MultipleContentSections  
How to use multiple content sections

Introduction

The 1/28/2008 Gadget specification introduces support for multiple content sections in a single gadget XML file. This page provides example code for utilizing this functionality.

Details

You are now allowed to include more than one <Content> section in a gadget XML file. All Content sections should be siblings in the document tree, and may use the optional parameter view= to define the views in which they should render.

Two content sections

The following code shows a superficial example.

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Multiple Content Sections">
    <Require feature="opensocial-0.7" />
  </ModulePrefs>
  <Content type="html" view="profile">
  <![CDATA[
    <h1>Profile</h1>
  ]]>
  </Content>
  <Content type="html" view="canvas">
  <![CDATA[
    <h1>Canvas</h1>
  ]]>
  </Content>
</Module>

The output on the above gadget is as follows:

Profile view

<h1>Profile</h1>

Canvas view

<h1>Canvas</h1>

Any other views that are not canvas or profile

no content is displayed

Content sections with multiple views specified

Content sections may specify multiple views, separated by commas:

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Multiple Content Sections (version 2)">
    <Require feature="opensocial-0.7" />
  </ModulePrefs>
  <Content type="html" view="canvas,profile">
  <![CDATA[
    <h1>Canvas and Profile</h1>
  ]]>
  </Content>
</Module>

The output on the above gadget is as follows:

Profile view

<h1>Canvas and Profile</h1>

Canvas view

<h1>Canvas and Profile</h1>

Any other views that are not canvas or profile

no content is displayed

Content section with view specified and no default content section

If you specify a content section with a view parameter, that content section is only shown on that view. Without specifying a default content section, other views will not display any content.

<?xml version="1.0" encoding="UTF-8" ?>
<Module>  
  <ModulePrefs title="Multiple Content Sections (version 2)">
    <Require feature="opensocial-0.7" />
  </ModulePrefs>
  <Content type="html" view="profile">
  <![CDATA[
    <h1>Profile</h1>
  ]]>        
  </Content>
</Module>

The output on the above gadget is as follows:

Profile view

<h1>Profile</h1>

Canvas view

no content is displayed

Any other views that are not canvas or profile

no content is displayed

Content section with view specified and a default content section

To specify a default content section, simply define a content section with no view parameter.

<Module>  
  <ModulePrefs title="Multiple Content Sections (version 2)">
    <Require feature="opensocial-0.7" />
  </ModulePrefs>
  <Content type="html" view="profile">
  <![CDATA[
    <h1>Profile</h1>
  ]]>        
  </Content>
  <Content type="html">
  <![CDATA[
    <h1>Default</1>
  ]]>
  </Content>
</Module>

The output on the above gadget is as follows:

Profile view

<h1>Profile</h1>

Canvas view

<h1>Default</h1>

Any other views that are not canvas or profile

<h1>Default</h1>

Full example

You can use all of these techniques in one gadget file.

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Multiple Content Sections (version 2)">
    <Require feature="opensocial-0.7" />
  </ModulePrefs>
  <Content type="html" view="profile">
  <![CDATA[
    <h1>Profile</h1>
  ]]>
  </Content>
  <Content type="html" view="canvas">
  <![CDATA[
    <h1>Canvas</h1>
  ]]>
  </Content>
  <Content type="html" view="canvas,profile">
  <![CDATA[
    <h2>This shows up in canvas and profile views</h2>
  ]]>
  </Content>
  <Content type="html">
  <![CDATA[
    <h1>Default</h1>
    <h2>The content in this section only shows up if no other content sections are applicable</h2>
  ]]>
  </Content>
</Module>

The output on the above gadget is as follows:

Profile view

<h1>Profile</h1>
<h2>This shows up in canvas and profile views</h2>

Canvas view

<h1>Canvas</h1>
<h2>This shows up in canvas and profile views</h2>

Any other views that are not canvas or profile

<h1>Default</h1>
<h2>The content in this section only shows up if no other content sections are applicable</h2>

Comment by suhaib798, Jul 14, 2008

bold

Comment by dpkkbsht, Jul 21 (3 days ago)

A very fruitful article/doc for the begineers

Comment by NeoAnderson123, Yesterday (34 hours ago)

Excellent article for the beginners...

Need more articles like this one..!


Sign in to add a comment