Michelle; I know how frustrating it can be when you don’t have a handle on a piece of code.
OK - what we are dealing with here is a php ’switch’ statement. I’ll comment it for you;
<?php // this is the opening tag required for all php code
$curPageNum = $modx->documentIdentifier; // this is getting the page id from MODx and placing it in the variable $curPageNum (current page number a variable I created to hold the ID)
switch($curPageNum){ // here we are saying" look at $curPageNum and depending on what ID it is do something.
case 1: // First try page ID number 1 and if it is pass the code to $output.
$output='<h3>Articles</h3>[[Ditto? &parents=`2` &summarize=`4` &tpl=`SidebarTemplate`&dateFormat=`%d %B, %Y`]]';
break; // If it is not page ID number 1 then go to the next statement and try that, and so on till it gets to the end.
default: // if there is no default statement it just falls off the end to the return statement.
}
return $output;
?>
So where you went wrong is you didn’t ask the switch statement to test $curPageNum for a desired page number ID. A switch statement is a series of ’if’ statements if theis is true then do this else try the next case etc.
Change it to this;
<?php
$curPageNum = $modx->documentIdentifier;
switch($curPageNum){
case 1: // whatever the document ID for your "home" page is
$output='what markup you want it to do goes here';
return $output;
?>
You don’t want to switch by chunk name but by document ID - ie; what page are you are wanting to put the content on?
So take the markup that you would have placed in that column in the template and put it into the statement you want to pass to $output.
For example in my original template I had this markup for my sub-column;
<div id="content-extra">
[!WebLogin? &tpl=`DF_Login` &loginhomeid=`[(site_start)]`!]
<h3>Recent Articles</h3>
[[Ditto? &summarize=`3` &total=`5` &startID=`65` &tpl=`news`]]
<h3>Search</h3>
[!AjaxSearch? &AS_showResults=`0`!]
[!WebLogin? &tpl=`DF_Login` &loginhomeid=`[(site_start)]`!]
</div> <!-- end of content-extra -->
I decided I didn’t want news on every page but the first page. So I deleted all of the calls except login
and replaced them with my snippet {{SidebarContent}}
So now i have;
<div id="content-extra">
<h3>Search</h3>
[!AjaxSearch? &AS_showResults=`0`!]
{{SidebarContent}}
</div> <!-- end of content-extra -->
and for example for my case 1: (my home page ID) I have this;
case 1:
$output='<h3>Articles</h3>[[Ditto? &parents=`2` &summarize=`4` &tpl=`SidebarTemplate`&dateFormat=`%d %B, %Y`]]';
break;
which just puts the news summary on the first page. On other pages I use a combos of the other deleted calls.
Sorry for the long post. Is this more clear?
Cheers,
Hal Davey