SmartBuilding How-to
From Sense/Net 6.0 Wiki
In this tutorial, you will create two simple SmartPages for displaying content data, and learn how to utilize the Workspace Content Type as a point of aggregation. To learn what a SmartPage is, see this explanation.
Contents |
[edit] Create a Smart Page
[edit] Create the Content
First off, we need data to display. Let us create a simple Content Type.
- Open the Content Explorer
- Click New Content in the toolbar
- Select Content Type Definition from the list of Content Types
- Paste the following xml into the textbox that appears.
- Click Create. Congratulations, you have created the type.
<ContentType name="Artist" parentType="GenericContent" handler="SenseNet.ContentRepository.GenericContent" xmlns="http://schemas.sensenet.hu/SenseNet/ContentRepository/ContentTypeDefinition"> <Title>Artist</Title> <Description>Content type for storing data on musicians</Description> <Fields> <Field name="FullName" type="ShortText"> <Title>Full Name</Title> <Bind property="DisplayName" /> </Field> <Field name="Discography" type="LongText"> <Title>Discography</Title> <Description>Discography in HTML format</Description> </Field> </Fields> </ContentType>
Now that we have defined the Content Type, let's make an Artist Content to display!
- Navigate to /YourInternet
- Click New Content and select Artist
- Let's say, enter Jacko for Name, and Michael Jackson for Full Name. Feel free to enter a simple Discography, but that is not necessary for now.
- Click Create
[edit] Create the renderer
Currently the prototype portlets created for SmartPages primarily support XSLT Renderers instead of Content Views, so let's create a simple renderer for our Content Type.
- Navigate to /Root/System/SystemPlugins/Renderers. This is where Xslt renderers should be kept.
- Create a new Folder named GenreWs
- In that folder, Create a new File named Artist.xslt
- Enter the following into the Binary field of your file, and click Save
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:snc="sn://SenseNet.Portal.UI.ContentTools" xmlns:snf="sn://SenseNet.Portal.UI.XmlFormatTools" exclude-result-prefixes="msxsl"> <xsl:output method="html" indent="yes" omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:call-template name="Main"> <xsl:with-param name="Context" select="/Content" /> </xsl:call-template> </xsl:template> <xsl:template name="Main"> <xsl:param name="Context" select="/Content" /> <div> <p> <strong>Name:</strong> <xsl:value-of select="$Context/Fields/FullName" /> </p> <div> <h3>Discography:</h3> <xsl:value-of select="$Context/Fields/Discography" disable-output-escaping="yes"/> </div> </div> </xsl:template> </xsl:stylesheet>
[edit] Create the page
Now that we have our Content Type, let's create a Smart Page to display it.
- In the Content Explorer, navigate to /Root/System/Apps
- Click New Content and select Page
- Name the Page Artist, and select any of the Page Templates available
- That's all you need to enter right now, click Create
We now have a Smart Page to display Artists.
Now, enter the following URL into a new tab of your browser:
An almost empty page should show up.
- Now, open the Portal Remote Control
- Click Add Portlet
- Select the Context bound Content Portlet prototype
- Place the Portlet in a comfortable location, and open its Edit dialog
- Set Bind to Current Content
- Set RenderingMode to Xslt
- Enter /Root/System/SystemPlugins/Renderers/GenreWs/Artist.xslt as the Xslt renderer path
- Enter Artist details as the Title of the Portlet
- Click Ok and Publish the Page
You should now see Name: Michael Jackson, with anything you entered as Discography shown below. Congratulations, your SmartPage is fully operational.
|
Important:
Be aware of what the previous example implies! If you edit the layout of a SmartPage while looking at a Content node, the changes will be saved into the SmartPage itself, and will affect all Content nodes displayed with that particular Page.
|
[edit] Create a Workspace
Now, let's create a Workspace to store Artists. The Workspace Content Type is a point of aggregation, which serves as a collection of items below it, and an easily accessible root for these items.
[edit] Create a Workspace Type
- In the Content Explorer, click Create
- From the list, select Content Type
- Paste the following xml into the textbox that appears.
- Click Create
<ContentType name="GenreWorkspace" parentType="Workspace" handler="SenseNet.Portal.Workspaces.Workspace" xmlns="http://schemas.sensenet.hu/SenseNet/ContentRepository/ContentTypeDefinition"> <Title>Genre Workspace</Title> <Description>Workspace type for storing Artist Contents of a specific Genre</Description> <Fields></Fields> </ContentType>
You might notice that we haven't defined any new Fields, and we might even have used the base Workspace Content Type. That is not exactly true, though. We created this Content Type so we can define a special SmartPage for it.
[edit] Create the Genre Workspace SmartPage
- In the Content Explorer, navigate to /Root/System/Apps
- Click New Content and select Page
- Name the Page GenreWorkspace, and select any of the Page Templates available
- Click Create
Now that we have created the Page, we need to set it up properly. With the Artist page, we defined an Artist Content first, and accessed the SmartPage for editing by navigating to that Content. This time, we'll try something different.
- Open a new browser window, and navigate to http://{your.Sense/Net.6.0.host}/Root/System/Apps/Genreworkspace
- An almost empty page should show up. In the Portal Remote Control, click Add Portlet
- Select the Context bound Content Collection Portlet prototype
- Place the Portlet in a comfortable location, and open its Edit dialog
- Set Bind to Current Content
- Enter Artists as the Bind_RelativeContextPath. This is a folder under the Workspace that we'll be creating soon.
- Set RenderingMode to Xslt
- Enter /Root/System/SystemPlugins/Renderers/WsCommon/RecentDocs.xslt as the Xslt renderer path. This is a Renderer for displaying folder contents on a dashboard-style page.
- Enter Artists as the Title of the Portlet
- Click Ok and Publish the Page
You should now see either and empty Portlet, or a Portlet containing an error message. This is completely natural, as there is no Content for the SmartPage to display right now.
[edit] Create the Workspace itself
- In the Content Explorer, navigate to /YourInternet/Workspaces
- Create a new GenreWorkspace, and name it Pop
- Under the Workspace, Create a new Folder named Artists
- Copy or move the Jacko Content you have created previously into this folder.
- Feel free to populate the folder with more Artist Contents.
- Navigate to http://{your.Sense/Net.6.0.host}/Workspaces/Pop
You should now see your GenreWorkspace SmartPage, with all the Artist Contents you have created displayed in the single Portlet on it. Click on Jacko. The Artist SmartPage should open, displaying the details of the Content we created earlier.
[edit] Make the Artist SmartPage Workspace-aware
Now, let's see what makes Workspaces special. You should now see a perfectly working Artist SmartPage. It's still a bit bland though, with that single Portlet. Let's spice it up a bit!
- Open the Portal Remote Control, and click Add Portlet
- Select the Context bound Content Portlet prototype
- Place the Portlet in a comfortable location on the side of the Page, and open its Edit dialog
- Set Bind to Current Workspace
- Set RenderingMode to Xslt
- Enter /Root/System/SystemPlugins/Renderers/WsCommon/SiteMenu.xslt as the Xslt renderer path.
- Enter Navigation as the Title of the Portlet
- Click Ok
You should now see a menu in the new Portlet, showing Artists, as the single subfolder of the Pop Workspace. You have linked to the Workspace from a Content inside it. No matter where this SmartPage is called from, this Portlet will always bind to and display the immediate children of the nearest Workspace - or Site, in the absence of a workspace - above it.
- Now, click Add Portlet again.
- Select the Breadcrumb Trail Portlet
- Place it at the top of the Page
- Now, click Publish on the Portal Remote Control
This should show Workspaces > Pop > Artists > Michael Jackson.
[edit] Spicing things up
I hope you got a hang of the basics of the Smart Application model and Workspaces. You might try the following to further your understanding of these topics:
- Create a Rock and Classic GenreWorkspace, populate them, and examine the behavior of Portlets
- Create an Album Content Type, a SmartPage to display it, and populated Albums folders under your GenreWorkspaces.
- Create SmartPages for Editing these Content Types.
- Examine the existing demo Workspaces in your the Sense/Net installation, and try to understand the hows and whys of the configuration of the Portlets on them.
