Last active
April 29, 2025 06:00
-
-
Save patrickatwsrn/855b7908313703d43f44aa5e4198d9ce to your computer and use it in GitHub Desktop.
MODX: Redirect to parent resource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Purpose: Redirect a child resource that is only used to structure content of its parent. | |
Usage: Add this snippet to your child template | |
[[!parentRedirect? | |
&parent=`[[*parent]]` | |
&alias=`[[*alias]]` | |
]] | |
Result: If a resource with this snippet inside its template is viewed, it will be redirected to its parent resource. | |
If you add an alias based on id to your output, the viewport will automatically home in on the content of your child resource. | |
*/ | |
$url = $modx->makeUrl($parent, '', '', 'https')."#".$alias; | |
$modx->sendRedirect($url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment