Skip to content

Instantly share code, notes, and snippets.

@patrickatwsrn
Last active April 29, 2025 06:00
Show Gist options
  • Save patrickatwsrn/855b7908313703d43f44aa5e4198d9ce to your computer and use it in GitHub Desktop.
Save patrickatwsrn/855b7908313703d43f44aa5e4198d9ce to your computer and use it in GitHub Desktop.
MODX: Redirect to parent resource
<?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