Hi All,
First post in the In-Development forum, so all the usual nerves. I have had a problem with allowing users to browse for a file as a weblink. There were several suggestions available (e.g using manager manager to sync the two fields , or a file browser plugin) though I have not had too much luck with these.
As a result i put together a simple snippet (while looking into First Child Redirect) that can do this for us. The idea is that you add a tv to a template, which will eventually link to a file (e.g a file tv, image etc) and then call the snippet in the resource body (yes! no weblink).
[!SendMeToATV? &dataPath=`tvOrPathToRedirectTo` !]
and it will redirect you to the path. Currently this only works with relative URL’s (and we pre-pend the site_url variable to it) and then send the redirect.
As i say i was looking at FirstChildRedirect while playing with this idea so it is just some variable changes. But i was thinking in the future you could re-direct to the tv of the first child (or other document) so that it can take advantage of published and unpublished dates.
Is this useful at all? Thoughts, Comments, Suggestions welcome
Al
Snippet Code:
<?php
/*
* @name SendMeToATV
* @author Alan Graham <[email protected]>
* @based upon FirstChildRedirect (Jason Coward / Ryan Thrash)
* @license Public Domain
* @version 0.0001
*
* @parameters
* dataPath - to be specified as the path that the Redirect needs to go to,
* this can be TV, Plan Text or Otherwise. Currently only relative URL's
* to the modx Site Start
*
* failureUrl - defaults to the modx Site Start but can be set to any other
* document ID
*/
$dataPath = (isset($dataPath))? $dataPath: 'none';
$failureUrl= (isset($failureUrl))? $faliureUrl: $modx->makeUrl($modx->config['site_start']);
if ($dataPath != 'none') {
$sendMe = $modx->config['site_url'] . $dataPath;
} else {
$sendMe = $failureUrl;
}
return $modx->sendRedirect($sendMe);
?>