Last modified by Simon Urli on 2023/10/10

<
From version < 40.7 >
edited by Silvia Macovei
on 2009/09/29
To version < 41.1 >
edited by Silvia Macovei
on 2009/09/29
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -56,7 +56,7 @@
56 56  1.1 Create the FAQ Class
57 57  
58 58  * On the Class Editor wizard entry page (XWiki.XWikiClasses), under the heading "Create a new data type", enter the following web space and class name:
59 -** Space: FAQs
59 +** Space: FAQ
60 60  ** Class: FAQ
61 61  
62 62  {image:CreateANewClass.PNG}
... ... @@ -64,20 +64,22 @@
64 64  * Click the "Create this Class" button. You should then see a code page with the following code:
65 65  
66 66  {code:none}
67 -## replace Main with the Space where you want your documents to be created
68 -## replace the default parent with the one of your choice
69 -## Save this template using the ?Save? button
70 -#set( $class = $doc.name.substring(0,$doc.name.indexOf("Class")))
71 -#set($defaultparent = "XWiki.${class}Class")
72 -#set($defaultweb = "Main")
73 -#includeForm("XWiki.ClassSheet")
67 +{{velocity}}
68 +## Replace Main with the Space where you want your documents to be created.
69 +## Replace the default parent with the one of your choice and save the document.
70 +##
71 +#set($className = $doc.name.substring(0, $doc.name.indexOf("Class")))
72 +#set($defaultParent = "${doc.space}.${className}Class")
73 +#set($defaultSpace = 'Main')
74 +{{/velocity}}
75 +{{include document="XWiki.ClassSheet"/}}
74 74  
75 75  {code}
76 76  
77 -In the code, change the word "Main" with the name of the space where you want you FAQ pages to be created as the commented instructions in the page code suggest. Replace the word "Main" with the word "FAQs". The line of code should now look like this:
79 +In the code, change the word "Main" with the name of the space where you want you FAQ pages to be created as the commented instructions in the page code suggest. Replace the word "Main" with the word "FAQ". The line of code should now look like this:
78 78  
79 79  {code:none}
80 -#set($defaultweb = "FAQs")
82 +#set($defaultSpace = 'FAQ')
81 81  
82 82  {code}
83 83  
... ... @@ -128,37 +128,21 @@
128 128  
129 129  {code:none}
130 130  
131 -11. You can modify this page to customize the presentation of your object
132 -11. at first you should keep the default presentation.
133 -11. Save this template using the save button.
133 +{{velocity}}
134 +## You can modify this page to customize the presentation of your object.
135 +## At first you should keep the default presentation and just save the document.
136 += Document $doc.name =
134 134  
135 -1 Document $doc.name
138 +#set($class = $doc.getObject('FAQ.FAQClass').xWikiClass)
136 136  
137 -## Change class name to your class name
138 -#set($class = $doc.getObject("XWiki.MyClass").xWikiClass)
139 -#set($hasProps = false)
140 140  #foreach($prop in $class.properties)
141 - #if($velocityCount == 1)
142 - #set($hasProps = true)
143 - <dl>
144 - #end
145 -<dt> ${prop.prettyName} </dt>
146 -<dd>$doc.display($prop.getName())</dd>
141 + ; $prop.prettyName
142 + : $doc.display($prop.getName())
147 147  #end
148 -#if($hasProps)
149 - </dl>
150 -#end
144 +{{/velocity}}
151 151  {code}
146 +* Let's take a moment now and analyze the code: with the line we just modified we retrieve the FAQ.FAQClass from the wiki and then we iterate through all its properties and display their values for the current document in a definition list. As we mentioned, XWiki provides a mechanism that help us create sheets used for both view and edit mode: this is the display function used in the line: {code:none} : $doc.display($prop.getName()){code} It detects the current mode (edit or view) and displays the property referenced by it's argument as the mode dictates: for view, it is the value of the property, for edit it is a form field that will allow the user to edit it. This way we can use a single Design Sheet for both displaying and editing our FAQs. See the [XWiki API reference > DevGuide.API] and [XWiki Scripting > DevGuide.Scripting] pages for more details.
152 152  
153 -* Change the class name ~~XWiki.MyClass~~ in the code to ~~FAQ.FAQClass~~ so that the line looks like this:
154 -
155 -{code:none}
156 -## Change class name to your class name
157 -#set($class = $doc.getObject("FAQ.FAQClass").xWikiClass)
158 -{code}
159 -
160 -* Let's take a moment now and analyze the code: with the line we just modified we retrieve the FAQ.FAQClass from the wiki and then we iterate through all its properties and display their values for the current document in a definition list. As we mentioned, XWiki provides a mechanism that help us create sheets used for both view and edit mode: this is the display function used in the line: {code:none}<dd>$doc.display($prop.getName())</dd>{code} It detects the current mode (edit or view) and displays the property referenced by it's argument as the mode dictates: for view, it is the value of the property, for edit it is a form field that will allow the user to edit it. This way we can use a single Design Sheet for both displaying and editing our FAQs. See the [XWiki API reference > DevGuide.API] and [XWiki Scripting > DevGuide.Scripting] pages for more details.
161 -
162 162  * Click 'Save & View'.
163 163  
164 164  1.1 Create the Authoring Template
... ... @@ -171,13 +171,11 @@
171 171  * Click on the 'Create the document template' button. The Authoring Template will be created with the following page code:
172 172  
173 173  {code:none}
174 -## Replace MyName with the real class name.
175 -## Save this template using the save button.
176 -#includeForm("XWiki.MyNameSheet")
160 +{{include document="FAQ.FAQSheet"/}}
177 177  {code}
178 178  
179 -* As the comments instruct, change the words ~~MyName~~ with ~~FAQ~~ so that instead of having ~~XWiki.MyNameSheet~~, you will have ~~FAQ.FAQSheet~~. In this case, we changed the space preceding the page name also because we want all of our FAQ page objects to reside in a unique wiki web space.
180 -* Click 'Save & Continue' to save the document. Remember that all our documents will be copies of the Authoring Template used as a prototype so the content we just saved will be copied in all our FAQs documents and will execute the Design Sheet code in the context of the current document. See the [dedicated page > DevGuide.IncludeInVelocity] for more information regarding this technique.
163 +* In this case, we changed the space preceding the page name also because we want all of our FAQ page objects to reside in a unique wiki web space.
164 +* Remember that all our documents will be copies of the Authoring Template used as a prototype so the content will be copied in all our FAQs documents and will execute the Design Sheet code in the context of the current document. See the [dedicated page > DevGuide.IncludeInVelocity] for more information regarding this technique.
181 181  * Now, we need to associate the prototype object with this document to turn it into a true authoring template.
182 182  * On the right side, in the Choose editor list, click ~~Objects~~.
183 183  * In the Add Object panel on the right, select FAQ.FAQClass from the drop-down and then click 'Add Object from this Class'. The ~~Question~~ and ~~Answer~~ form fields appear on the page.
... ... @@ -208,8 +208,8 @@
208 208  
209 209  If you want to display the FAQ question instead of the FAQ document name in the summary area, you can proceed as follows:
210 210  * Edit the content of the FAQ.FAQClass page
211 -* Replace the #\include\Form("XWiki.ClassSheet") with the content of the XWiki.ClassSheet (go to the XWiki.ClassSheet, edit the content and paste it instead of the #\includeForm command
212 -* Then, after the {code:none}#foreach ($item in $xwiki.searchDocuments($sql)){code} command add the following line {code:none}#set ($faq=$xwiki.getDocument(${item})){code} and replace the {code:none}[$item]{code} with {code:none}[${faq.display("question")}>${item}]{code} The line we added retrieves the document using the document name while the line we replaced displays the "question" property for the document instead of the document name.
195 +* Replace the {{include document="XWiki.ClassSheet"/}} with the content of the XWiki.ClassSheet (go to the XWiki.ClassSheet, edit the content and paste it instead of the include document command
196 +* Then, after the {code:none}#foreach ($item in $xwiki.searchDocuments($sql)){code} command add the following line {code:none}#set ($faq=$xwiki.getDocument(${item})){code} and replace the {code:none}[[$item]]{code} with {code:none}[[${faq.display("question")}>>${item}]]{code} The line we added retrieves the document using the document name while the line we replaced displays the "question" property for the document instead of the document name.
213 213  * Click "Save & View" and enjoy your new FAQ application.
214 214  
215 215  
... ... @@ -218,7 +218,7 @@
218 218  We don't want our users to have to search for this page using the search engine, so finally pick a spot on your Wiki and make a user-friendly link to FAQ.FAQClass. For example:
219 219  
220 220  {code:none}
221 -[Frequently Asked Questions (FAQs) > FAQ.FAQClass]
205 +[[Frequently Asked Questions (FAQs) >> FAQ.FAQClass]]
222 222  {code}
223 223  
224 224  
FAQClass4.PNG
Size
... ... @@ -1,1 +1,1 @@
1 -29.4 KB
1 +28.9 KB
Content
FAQClass5.PNG
Size
... ... @@ -1,1 +1,1 @@
1 -13.9 KB
1 +13.5 KB
Content

Get Connected