Hi. Many thanks for the snippet, it looks like it’ll prove very useful.
I’ve made a couple of very minor changes, necessary to allow me to use TVs on the current document without having to specify the doc ID.
Currently, your code A) sets the id to false if a non numerical urlParam is provided and B) requires the id in order to look for the * characters that indicate a TV is to be sourced.
There’s no need for B because MODx will default to using the current document id if it’s false and I think the preventing A results in behaviour that’s least surprising (in that one bad param won’t alter another good one).
Changes made to repo-1498.txt.
diff --git a/HEAD^:vCard.snippet.php b/HEAD:vCard.snippet.php
index 34b1250..ff321be 100644
--- a/HEAD^:vCard.snippet.php
+++ b/HEAD:vCard.snippet.php
@@ -77,8 +77,6 @@ $id = isset($id) ? $id : false;
$urlParam = isset($urlParam) ? $urlParam : 'id';
if (isset($_GET[$urlParam]) && is_numeric($_GET[$urlParam])) {
$id = $_GET[$urlParam];
-} else {
- $id = false;
}
@@ -92,7 +90,7 @@ foreach ($fields as $f) {
$input[$f] = isset($$f) ? $$f : '';
// If the value supplied is surrounded by *, e,g, *staffemail*, assume we are being told to use not a literal value here,
// but the value of a template variable
- if ($id && substr($input[$f], 0, 1) == '*' && substr($input[$f], -1, 1) == '*') {
+ if (substr($input[$f], 0, 1) == '*' && substr($input[$f], -1, 1) == '*') {
$tvname = substr($input[$f], 1, strlen($input[$f])-2); // remove the asterisk from each end
$doc_id = $id;
// if we have requested a parent TV value by prefixing the tv name with parent.
@@ -316,4 +314,4 @@ class vCard {
return $this->filename;
}
}
-?>
\ No newline at end of file
+?>
Thanks again.
Stephan