Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
---
2
layout: docs
3
title: "Example files"
4
date: 2020-01-21T13:00:00+08:00
5
draft: false
6
---
7
 
8
There may be times that we need to provide example implementations of the component being documented in order to further demonstrate how to use a component.
9
 
10
We need to put these files in `examples` folders. It helps organise things and makes the maintenance of the component library code easier by allowing us to distinguish examples from the actual component library code.
11
 
12
 
13
## Example pages
14
 
15
Example pages can be placed under the `componentlibrary/examples` folder.
16
 
17
See the `formfields.php` example page as an example:
18
 
19
```
20
componentlibrary
21
└── examples
22
     └── formfields.php
23
```
24
 
25
This can be embedded in the component's documentation page via iframe. For example in `componentlibrary/content/moodle/form-elements.md`:
26
 
27
```
28
<iframe src="../../../../examples/formfields.php" style="overflow:hidden;height:4000px;width:100%;border:0" title="Moodle form fields"></iframe>
29
```
30
 
31
## Example classes
32
 
33
Example classes can be placed under the `componentlibrary/classes/local/examples/[componentname]` folder.
34
 
35
In our form fields example, we have the `\tool_componentlibrary\local\examples\formelements\example` class under `componentlibrary/classes/local/examples/formelements`.
36
 
37
## Example templates
38
 
39
Example templates can be placed under the `componentlibrary/templates/examples/[componentname]` folder.
40
 
41
In our form fields example, we have the `tool_componentlibrary/examples/formelements/toggles` template under `componentlibrary/templates/examples/formelements`.
42
 
43
## Summary
44
 
45
Please put example files in their designated `examples` folders.
46
```
47
componentlibrary
48
└── classes
49
    └── local
50
        └── examples
51
            └── [component folder]
52
                └── [example classes]
53
└── examples
54
    └── [example page]
55
└── templates
56
    └── examples
57
        └── [component folder]
58
            └── [example templates]
59
```
60
 
61
For the form elements documentation, its example files are in the following `examples` folders.
62
```
63
componentlibrary
64
└── classes
65
    └── local
66
        └── examples
67
            └── formelements
68
                └── example.php
69
└── examples
70
    └── formfields.php
71
└── templates
72
    └── examples
73
        └── formelements
74
            └── toggles.mustache
75
```