|
Using Code Snippets
Compatibility: Sitefinity 3.7 Code Snippets are small pieces of predefined code that can be used to make it easier for Sitefinity users to create content that looks the same everywhere. Instead of having users create content from scratch, or letting users determine the CSS styles to use, a piece of code can be generated which users can fill without having to choose the correct style or format.
To be able to start using Code Snippets, you will have to go through three steps:
- Add Code Snippet button.
- Create Code Snippets.
- Use Code Snippets.
Add Code Snippet button
The Code Snippet button is not visible when Sitefinity is installed out of the box. In order to enable the button in the RAD Editor, the code for the button needs to be added to the EditorToolsFile.xml, which holds all the buttons that are displayed in the editor. The file can be found at the following location:
~/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml The file starts with a number of <tools> declarations. Scroll down to the place where you would like the new button and add the folowing piece of code:
<tool name="InsertSnippet" /> Save the file and upload if necessary. The Insert Code Snippet button is now visible in the RAD Editor. 
Create Code Snippets
In the same EditorToolsFile.xml that was used to add the button, there is a section called <snippets>. In that section, all necessary Code Snippets can be placed. The structure for every snippet should be the same: <snippet name="Descriptive name for your snippet"> <![CDATA[ HTML code for your snippet ]]> </snippet> Every snippet starts with <snippet name="">. This setting requires a descriptive name to be entered to identify each snippet in an easy way. Then the <![CDATA[ is used to make sure the HTML code is interpreted correctly in the XML file. Now the HTML code for the snippet is placed. To end the snippet the correct way the tags need to be closed by ]]> and </snippet>. Add all the snippets like this. Then save and upload the file if necessary.
Use Code Snippets
After the button has been made visible and the Code Snippets have been created, all that's left is to start using them! Select a page and choose to Edit this page. Insert or Edit a control that uses the RAD Editor. Place your cursor where you want the piece of code to be entered. Now click the Insert Code Snippet button to show a list of all available Code Snippets and click on the desired Code Snippet to have it placed where the cursor is. 
|