Since its a Sunday, and anything useful I try to do seems to go pear shaped.
The direction so far....
// determine if first row,last row or a middle "default row".
$templateRow = "tplMiddleRow";
if($x < 3){ $templateRow = "tplFirstRow"; }
if($x > ($stop - 3)){ $templateRow = "tplLastRow"; }
// determine "left, center, or right"
switch($x % 3)
{
case 0;
$templatePosition = "Left";
break;
case 1;
$templatePosition = "Center";
break;
case 2;
$templatePosition = "Right";
break;
}
$currentTPL = $templateRow.$templatePosition;
Which I am intending to add to the function in the class like this...
function determineTPL($x, $stop, $id, $format, $templates) {
global $modx;
// determine current template
$currentTPL = "default";
/****** start hack ******/
// hack for three columns
// want to get a variable passed to the function,
// but don't know where it needs to come from yet
// so I will make one up
$numberColumns = 3;
if($numberColumns == 3){
// determine if first row,last row or a middle "default row".
$templateRow = "tplMiddleRow";
if($x < 3){ $templateRow = "tplFirstRow"; }
if($x > ($stop - 3)){ $templateRow = "tplLastRow"; }
// determine "left, center, or right"
switch($x % 3)
{
case 0;
$templatePosition = "Left";
break;
case 1;
$templatePosition = "Center";
break;
case 2;
$templatePosition = "Right";
break;
}
$currentTPL = $templateRow.$templatePosition;
/****** end hack ******/
}else{ // orginal two or one column stuff...
if ($x == 0) {
$currentTPL = "tplFirstRow";
}
if ($x % 2) {
$currentTPL = "tplAltRows";
}
if ($x == $stop -1) {
$currentTPL = "tplLastRow";
}
}
if ($id == $modx->documentObject['id']) {
$currentTPL = "tplCurrentDocument";
}
return $currentTPL;
}
However it keeps returning "tplCurrentDocument" due to this line in the code which I don’t understand the purpose of...
if ($id == $modx->documentObject['id']) {
$currentTPL = "tplCurrentDocument";
}
??? That would be the question I guess, what’s going on there?
This has been purely for learning purposes, I can’t imagine anyone want to make up nine templates to form the matrix, but it’s helped me get to know the snippet a lot better.
Code I was using ( outside of the ModX environment ) for testing...
<?
function determineTPL($x, $stop, $id, $format, $templates) {
global $modx;
// determine current template
$currentTPL = "default";
/****** start hack ******/
// hack for three columns
// want to get a variable passed to the function,
// but don't know where it needs to come from yet
// so I will make one up
$numberColumns = 3;
if($numberColumns == 3){
// determine if first row,last row or a middle "default row".
$templateRow = "tplMiddleRow";
if($x < 3){ $templateRow = "tplFirstRow"; }
if($x > ($stop - 3)){ $templateRow = "tplLastRow"; }
// determine "left, center, or right"
switch($x % 3)
{
case 0;
$templatePosition = "Left";
break;
case 1;
$templatePosition = "Center";
break;
case 2;
$templatePosition = "Right";
break;
}
$currentTPL = $templateRow.$templatePosition;
/****** end hack ******/
}else{ // orginal two or one column stuff...
if ($x == 0) {
$currentTPL = "tplFirstRow";
}
if ($x % 2) {
$currentTPL = "tplAltRows";
}
if ($x == $stop -1) {
$currentTPL = "tplLastRow";
}
}
if ($id == $modx->documentObject['id']) {
// $currentTPL = "tplCurrentDocument";
}
return $currentTPL;
}
echo determineTPL(0,20,'','','')." 0<br />";
echo determineTPL(1,20,'','','')." 1<br />";
echo determineTPL(2,20,'','','')." 2<br />";
echo determineTPL(3,20,'','','')." 3<br />";
echo determineTPL(4,20,'','','')." 4<br />";
echo determineTPL(5,20,'','','')." 5<br />";
echo determineTPL(6,20,'','','')." 6<br />";
echo determineTPL(7,20,'','','')." 7<br />";
echo determineTPL(8,20,'','','')." 8<br />";
echo determineTPL(9,20,'','','')." 9<br />";
echo determineTPL(10,20,'','','')." 10<br />";
echo determineTPL(11,20,'','','')." 11<br />";
echo determineTPL(12,20,'','','')." 12<br />";
echo determineTPL(13,20,'','','')." 13<br />";
echo determineTPL(14,20,'','','')." 14<br />";
echo determineTPL(15,20,'','','')." 15<br />";
echo determineTPL(16,20,'','','')." 16<br />";
echo determineTPL(17,20,'','','')." 17<br />";
echo determineTPL(18,20,'','','')." 18<br />";
echo determineTPL(19,20,'','','')." 19<br />";
?>
Additions to the snippet, should someone someday want to use this...
// ---------------------------------------------------
// Additional Template Parameters for Three Columns
// ---------------------------------------------------
$tplFirstRowLeft = isset($tplFirstRowLeft) ? $modx->getChunk($tplFirstRowLeft) : $tpl;
// tpl for first row left
$tplFirstRowCenter = isset($tplFirstRowCenter) ? $modx->getChunk($tplFirstRowCenter) : $tpl;
// tpl for first row center
$tplFirstRowRight = isset($tplFirstRowRight) ? $modx->getChunk($tplFirstRowRight) : $tpl;
// tpl for first row right
$tplMiddleRowLeft = isset($tplMiddleRowLeft) ? $modx->getChunk($tplMiddleRowLeft) : $tpl;
// tpl for middle row left
$tplMiddleRowCenter = isset($tplMiddleRowCenter) ? $modx->getChunk($tplMiddleRowCenter) : $tpl;
// tpl for middle row center
$tplMiddleRowRight = isset($tplMiddleRowRight) ? $modx->getChunk($tplMiddleRowRight) : $tpl;
// tpl for middle row right
$tplLastRowLeft = isset($tplLastRowLeft) ? $modx->getChunk($tplLastRowLeft) : $tpl;
// tpl for last row left
$tplLastRowCenter = isset($tplLastRowCenter) ? $modx->getChunk($tplLastRowCenter) : $tpl;
// tpl for last row center
$tplLastRowRight = isset($tplLastRowRight) ? $modx->getChunk($tplLastRowRight) : $tpl;
// tpl for last row right
Noe I think of it, I didn’t even look around to see if this has been already covered.