You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/actions.md
+36-32Lines changed: 36 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Follow the prompts to add an action file to your add-on.
27
27
This will create an `Actions` folder inside our `Module` folder where will build out the code we want to run when a user hits our `ACT` URL. Inside our `Actions` folder the CLI will create a file with the same name as the method we defined when creating our action.
28
28
29
29
```
30
-
amazing_addon
30
+
amazing_add_on
31
31
┣ Module
32
32
┃ ┣ Actions
33
33
┃ ┃ ┗ [MethodName].php
@@ -164,7 +164,11 @@ public function up()
164
164
}
165
165
...
166
166
```
167
-
- To set an action as CSRF exempt on creation, use the `--csrf_exempt` or `-c` flag in the CLI: `$ php system/ee/eecli.php make:action --csrf_exempt`
167
+
- To set an action as CSRF exempt on creation, use the `--csrf_exempt` or `-c` flag in the CLI:
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
196
190
```
197
191
192
+
This creates our required files. Now we had some functionality to our action which will add the first and last name submitted from a form to our custom database table.
193
+
198
194
Our action code:
199
195
200
196
```
@@ -225,6 +221,22 @@ class ExampleAction extends AbstractRoute
**A note about action IDs.** For the example above, we looked up the action ID in the database. However, the action ID of your method may be different in your database than someone else as the IDs are auto-incremented by the database on insertion. Therefore, it's always best practice to fetch your action ID for use in a template by using the [`fetch_action_id()`](/development/legacy/libraries/cp.md#fetch_action_idclass-method) method from the `CP Class` library.
229
241
230
242
We would do this in our add-on with something like this:
In this next example we are just creating an endpoint which will be reachable from servers outside of our domain. We are going to expect the application to use cURL or similar libray to post an ID to our endpoint. Upon receiving the request our action will return the name of the entry matching the ID if it exists.
240
252
253
+
Create our action:
254
+
```
255
+
$ php system/ee/eecli.php make:action --install
256
+
What is the action name? ExampleAction
257
+
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
258
+
```
259
+
241
260
Our action code:
242
261
243
262
```
@@ -279,9 +298,7 @@ However, when I attempt to reach this endpoint from another application I get an
279
298
280
299
The request:
281
300
```
282
-
curl --location --request POST 'https://anamzingwebsite.test/?ACT=41' \
283
-
--form 'id="1
284
-
"'
301
+
curl --location --request POST 'https://anamzingwebsite.test/?ACT=41' --form 'id="1"'
285
302
```
286
303
287
304
The response:
@@ -298,21 +315,8 @@ The response:
298
315
</div>
299
316
...
300
317
```
301
-
This is because of the [`csrf_exempt` value](#exp_actions) mentioned above. To fix this we can go into the `exp_actions` table of our database and update the `csrf_exempt` column to `1`. However, to adjust for future installations we need to adjust the `$actions` array of our `upd` file.
302
-
303
-
Here we are going to set the `csrf_exempt` value on installation of our add-on.
304
-
```
305
-
public $actions = [
306
-
[
307
-
'class' => 'Demo_addon',
308
-
'method' => 'Example_Action',
309
-
'csrf_exempt` => true
310
-
]
311
-
];
312
-
```
318
+
This is because of the [`csrf_exempt` value](#cross-site-request-forgerycsrf-exemption) mentioned above. To fix this we can go into the `exp_actions` table of our database and update the `csrf_exempt` column to `1`.
313
319
314
320
Now when I send that same request, I simply get the entry title I requested.
315
321
316
-
WARN: **Warning:** Use caution when making an action csrf exempt. First ensure you really need to do so, then also provide some sort of key or validation to ensure the incoming request is not malicious.
Copy file name to clipboardExpand all lines: docs/development/custom-template-tags.md
+14-19Lines changed: 14 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Now, let's update the class to read the timezone that is passed in:
35
35
This will create an `Models/Tags` folder in your add-on.
36
36
37
37
```
38
-
amazing_addon
38
+
amazing_add_on
39
39
┣ Module
40
40
┃ ┗ Tags
41
41
┃ ┃ ┗ ExampleTag.php
@@ -66,26 +66,21 @@ As we can see, the CLI has correctly created a new class using our tag's name in
66
66
67
67
Inside of our class is the `process()` method. Anything we want to happen when our template tag is used should be placed inside this `process()` function.
68
68
69
-
After your tag is created, you can use your tag by just using `{exp:[tag_name]}`. In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
69
+
After your tag is created, you can use your tag by just using `{exp:[addon_name][tag_name]}`. In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
70
70
71
71
72
72
## Tag Construction
73
73
74
-
A typical ExpressionEngine tag looks like this:
74
+
A typical custom add-on tag looks like this:
75
75
76
-
{exp:channel:entries}
76
+
{exp:amazing_add_on:bold}
77
77
78
78
The first segment is the tag identifier: {exp:. It tells the template engine that it has just encountered a tag.
79
79
80
-
The second segment is the "family" name: `{exp:channel`. There are different families of tags: channel, comments, members, email, stats, etc. In programming terms, the second segment is the name of the 'class' that is instantiated by the tag.
81
-
82
-
The above example would tell the template engine to dynamically instantiate the "channel" class.
83
-
84
-
The third segment indicates the 'function' from within a particular family of tags: `{exp:channel:entries}`. This example would tell ExpressionEngine you want to use the "entries" method in the "channel" class.
80
+
The second segment is the add-on's name all lowercase and with no spaces or special characters. In this case, we're telling ExpressionEngine to look inside of the Amazing Add-On add-on.
85
81
86
-
A tag, therefore, mirrors an object oriented approach: `Class->method`:
82
+
The third segment indicates the tag from inside the add-on to use. In this case it is the `bold` tag.
87
83
88
-
{exp:class_name:method_name}
89
84
90
85
### Two Kinds of Tags
91
86
@@ -105,9 +100,9 @@ Tag pairs allow you to process the information contained between the tags. In th
105
100
Single Tags are the easiest template tags to create and process. Here we'll add a single tag to our add-on using the CLI. We'll name the tag Amazing Text.
106
101
107
102
```
108
-
php system/ee/eecli.php make:tag
103
+
php system/ee/eecli.php make:template-tag
109
104
What is the tag name? Amazing Text
110
-
What add-on is the tag being added to? amazing_add_on
105
+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
111
106
Tag created successfully!
112
107
```
113
108
@@ -160,9 +155,9 @@ You will be able to use this plugin anywhere in a Template. You can even put thi
160
155
To create this tag pair, we'll use the CLI similarly to how we created a single tag.
161
156
162
157
```
163
-
php system/ee/eecli.php make:tag
158
+
php system/ee/eecli.php make:template-tag
164
159
What is the tag name? bold
165
-
What add-on is the tag being added to? amazing_add_on
160
+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
166
161
Tag created successfully!
167
162
```
168
163
@@ -238,9 +233,9 @@ We will allow the following parameter choices:
238
233
-`type="italic"`
239
234
240
235
```
241
-
php system/ee/eecli.php make:tag
236
+
php system/ee/eecli.php make:template-tag
242
237
What is the tag name? format
243
-
What add-on is the tag being added to? amazing_add_on
238
+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
244
239
Tag created successfully!
245
240
```
246
241
@@ -304,7 +299,7 @@ First, generate the tag (we're calling our tag "date and time" and adding it to
304
299
```
305
300
php system/ee/eecli.php make:template-tag
306
301
What is the tag name? date and time
307
-
What add-on is the tag being added to? amazing_add_on
302
+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
308
303
Tag created successfully!
309
304
```
310
305
@@ -382,4 +377,4 @@ The current date is: November 15, 2022
382
377
The current time is: 02:40 PM
383
378
```
384
379
385
-
TIP: Of course, this is only the begining of what you can do with variables in your tag. We created single variables here, but you can create pair variables and much more. For more information about this, and manipulating the tagdata in your plugin, check out the [Template Class](development/legacy/libraries/template.md).
380
+
TIP: Of course, this is only the beginning of what you can do with variables in your tag. We created single variables here, but you can create pair variables and much more. For more information about this, and manipulating the tagdata in your plugin, check out the [Template Class](development/legacy/libraries/template.md).
Copy file name to clipboardExpand all lines: docs/development/extensions.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,11 +34,11 @@ TIP: Files that interact with ExpressionEngine core hooks are referred to as "ex
34
34
This will create an `ext[addon_name].php` file in our add-on along with an `Extensions` folder where will build out the code we want to run when we interact with a core hook. Inside our `Extensions` folder the CLI will create a file with the same name as the core hook we plan to use.
35
35
36
36
```
37
-
amazing_addon
37
+
amazing_add_on
38
38
┣ Extensions
39
39
┃ ┣ [HookName].php
40
40
┃ ...
41
-
┗ ext.amazing_addon.php
41
+
┗ ext.amazing_add_on.php
42
42
```
43
43
44
44
TIP: A single add-on can interact with as many hooks as you want.
@@ -55,12 +55,12 @@ Here we have added the ability to interact with the [`typography_parse_type_end(
0 commit comments