Skip to content

Commit

Permalink
Update modx.sendforward.md
Browse files Browse the repository at this point in the history
another example has been added
  • Loading branch information
ant-tar authored Jun 23, 2024
1 parent 89532e4 commit db2c2bd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions en/extending-modx/modx-class/reference/modx.sendforward.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ void sendForward (integer $id, [string|array $options = null], [boolean $sendErr
- `merge`: a way to merge the resource currently in `$modx->resource` with the target resource. The `content`, `pub_date`, `unpub_date`, `richtext`, `_content` and `_processed` values are excluded as well as the value of the [forward_merge_excludes](building-sites/settings/forward_merge_excludes) system setting. I'm not sure if this is supposed to be used out of the core and there's probably better ways to get data combined (eg: `setPlaceholder`) then merging.
- `$sendErrorPage` Whether we should skip the [sendErrorPage](extending-modx/modx-class/reference/modx.senderrorpage "modX.sendErrorPage") if the resource does not exist.

## Example
## Examples

Send the user to Resource ID 234 without actually changing the URL.
1. Send the user to Resource ID 234 without actually changing the URL.

``` php
$modx->sendForward(234);
```

Send user to 404 Error page, for actual page ID we use [error_page](building-sites/settings/error_page) system setting value. If there is no such value,
2. Send user to 404 Error page, for actual page ID we use [error_page](building-sites/settings/error_page) system setting value. If there is no such value,
the value of [site_start](building-sites/settings/site_start) will be used.

``` php
Expand All @@ -46,6 +46,19 @@ $options = array(
);
$this->sendForward($this->getOption('error_page', $options, $this->getOption('site_start')), $options, false);
```
3. Show replacement page, keeping original `pagetitle`, `introtext` and other fields. To do this, you just need to specify an additional array with keys:

``` php
$options = array(
'merge' => 1, // field gluing mechanism enabled
// original fields list that need to be excluded from the result
'forward_merge_excludes' => 'id,template,type,published,class_key'
);
$this->sendForward(15, $options);;
```
[forward_merge_excludes](building-sites/settings/forward_merge_excludes) setting manages source page fields that need to be excluded from the results. Next fields will definitely be added as well: `content,pub_date,unpub_date,richtext`

This is good approach if you want hide/protect some resources but left `pagetitle` and `description` for visitors and search crawlers.

## See Also

Expand All @@ -55,3 +68,4 @@ $this->sendForward($this->getOption('error_page', $options, $this->getOption('si
- [modX.sendErrorPage](extending-modx/modx-class/reference/modx.senderrorpage "modX.sendErrorPage")
- [modX.sendUnauthorizedPage](extending-modx/modx-class/reference/modx.sendunauthorizedpage)
- [error_page](building-sites/settings/error_page)
- [forward_merge_excludes](building-sites/settings/forward_merge_excludes)

0 comments on commit db2c2bd

Please sign in to comment.