We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15523
    • 16 Posts
    Hello,

    I am lost here if anyone can help. Please forgive my ignorance, but I am a dummy with php, but I really like MODx, so I’m hoping that I can get this figured out. Anyway, I have three questions that I am just not finding answers to in the forum or documentation.

    1. I have a 2 column template that I am using, but the content on the left side will change with every page. So do I need to use "chunks" or TV’s? If I use chunks, then don’t I have to have multiple templates for each page? I was hoping to be able to use just one template. I am really lost trying to figure out when to use a chunk and when to use a TV.

    2. I didn’t install the "demo" site when I installed MODx on my server, so now I have no example of the rss feed page. Is there somewhere I can go that will teach me how to create a rss feed for the blog part of my site?

    3. Can you use your own php email forms with MODx? I had tried to do this, but when I submitted the form for testing, it came back to me blank and I set it up exactly like I had it on my static site before. (ps.... yes, I tried the eForm already, but couldn’t get it figured out for the life of me...lol)

    Thanks for taking the time to help,
    Michelle
      • 4310
      • 2,310 Posts
      Hello Michelle,

      1. I have a 2 column template that I am using, but the content on the left side will change with every page. So do I need to use "chunks" or TV’s? If I use chunks, then don’t I have to have multiple templates for each page? I was hoping to be able to use just one template. I am really lost trying to figure out when to use a chunk and when to use a TV.

      Make sure you have the TV [*content*] in the left column of your template, you will then be able to use the manager to edit each pages left column area as the main content

      2. I didn’t install the "demo" site when I installed MODx on my server, so now I have no example of the rss feed page. Is there somewhere I can go that will teach me how to create a rss feed for the blog part of my site?

      Create a new page and use this snippet call on it...
      [!NewsFeed?newsfolder=`2` &commentschunk=`FormBlogComments`!]
      where 2 is the ID of your blog folder/parent page
      The page should use a blank template, check.....Document Settings - General -Uses Template - Blank
      Then it should be xml, so Document Settings - Page Settings -Content Type - text/xml
      This page will output an xml RSS feed of all the blog posts in your folder/parent page

      3. Can you use your own php email forms with MODx? I had tried to do this, but when I submitted the form for testing, it came back to me blank and I set it up exactly like I had it on my static site before. (ps.... yes, I tried the eForm already, but couldn’t get it figured out for the life of me...lol)

      eForm is quite easy to set up once you’re used to MODx, you don’t need most of the parameters.
      You could do a reinstall with the demo content and use the demo pages as a starting point for the learning curve.
      I learnt by using the demo content and modifying it until it didn’t work!
      It may seem a lot at the start but you will soon get up to speed.
      Good luck,
      David
        • 11678
        • 160 Posts
        Hi Michelle,
        I have a 2 column format that I am changing the content on the small col on each page this way;
        I have a snippet that uses document (page) ID to determine what is going there. The snippet is just php code:
        <?php
        $curPageNum = $modx->documentIdentifier;
        switch($curPageNum){
        	case 1:    
        		$output='<h3>Articles</h3>[[Ditto? &parents=`2`  &summarize=`4` &tpl=`SidebarTemplate`&dateFormat=`%d %B, %Y`]]';
        		break;
        	case 77:    
        		$output=' ';
        		break;
        	case 78:
        		
        	dafault:
        }
        return $output;
        ?>

        where each case statement is a document ID. Just add as many case statements as you need and put your html markup into the output statement. NOTE: there are single quotes (’) surrounding the output statement. You can include chunks and snippets in the call. It works great. Go to the snippet page of the manager, select new snippet give it a name and paste in the php code. Then just place a call to the snippet where you want the sidebar content to go. I have one such snippet I use to change the header image on every page. If you use TVs they are template specific and are going to place the same content on every page using the same template.
        Using the snippet allows you to use only one template for all your pages vs having loads of different templates to vary the content.
        Cheers,
        Hal D
          "Today’s headlines are nothing more than whispers of history"
          • 15523
          • 16 Posts
          Thank you so much David and Hal for such helpful answers. I really appreciate your help, it means alot! smiley

          Have A Great Day!
          Michelle
            • 15523
            • 16 Posts
            Hal,

            I need your help again if you don’t mind? I am trying to use your php snippet that you gave me, but instead of pulling in documents, I need it to pull in just chunks. Is that possible? I tried playing around with the code, but have no clue as to what I am doing wrong here, I am out of ideas. Could you please take a look at the code and tell me what I have wrong here?

            <?php
            $curPageNum = $modx->documentIdentifier;
            switch($curPageNum){
            homeleft:
            $output=’{{leftsidehome}}’;
            break;
            aboutleft:
            $output=’place modx chunk here ’;
            break;
            servicesleft:
            $output=’place modx chunk here ’;
            break;
            portfolioleft:
            $output=’place modx chunk here ’;
            break;
            contactleft:
            $output=’place modx chunk here ’;
            break;
            newsblogleft:
            $output=’place modx chunk here ’;
            break;
            clientlist:
            $output=’place modx document id here ’;
            break;
            default:
            $output=’place modx chunk here ’;
            break;
            }
            return $output;
            ?>


            Thanks so much for your help! smiley
            Michelle
              • 24414
              • 45 Posts
              The snippet requires document IDs (the numbers next to the name of the document in the site tree view) to switch the content.

              Change homeleft/aboutleft/etc. for the document IDs of the pages you want to put the content into:

              <?php
              $curPageNum = $modx->documentIdentifier;
              switch($curPageNum){
              1:    
                    $output='{{homeChunk}}';
                    break;
              2:    
                    $output='{{aboutChunk}}';
                    break;
              default:
                    $output='{{defaultChunk}}';
                    break;
              }
              return $output;
              ?>
              


              Add the snippet to your document/template where you need the content to be displayed:

              [[snippetName]]
              


              If you plan to change the content of the chunks regularly a slightly easier/more flexible way to do this may be with Template Variables - you won’t have to dig into PHP just to change the chunk for a page.
                • 11678
                • 160 Posts
                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
                  "Today’s headlines are nothing more than whispers of history"
                  • 15523
                  • 16 Posts
                  Yeah!! I did it!! After reading the answers from you both, a "lightbulb" just turned on in my head and it all made sense . Whoohoo! Thank you Ram and Hal for helping me to understand this. It’s not really as hard as I made it out to be in the first place...lol, now its time for me to go purchase a good php book and learn more! smiley

                  Michelle laugh
                    • 11678
                    • 160 Posts
                    Michelle; There are tons of good php books out there but for starting out I like Larry Ulman’s "PHP and MySQL" a Peachpit Press book. You can usually find them for a good price at the Half-Price book store chain or thru Amazon.com And if you want to get really up to date try "Object Oriented PHP" by Peter Lavin, No Starch Press. Since MODx is going OO it might be a good idea. when PHP gets finished in version 6 it is going to be like Java - so why use PHP?
                    Cheers,
                    Hal Davey
                      "Today’s headlines are nothing more than whispers of history"
                      • 15523
                      • 16 Posts
                      Thanks Hal for the book recommendations, I will have to get those. Object Oriented PHP - wow, that sounds hard. Aw well, I guess nows as good as time as any to learn it. I will have to broaden my skills from just a designer I guess if I want to get anywhere these days...lol. Also, just want to say thank you again for taking the time to help me. I really do appreciate it smiley

                      Michelle