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

    I am completely new to Modx and to content managment systems. I have had a play arond with Drupal and enjoyed some success in terms of functionality but little by way of design and control.

    I managed to port my design to modx very easily have begin adding pages no problem. However I do Have a number of questions and will post them as seperated threads.


    I am using a ismple two coloumn layout - with main content on the left and the right reserved for special content.

    Now my question is, how do I set-up modx so I add content to the righthand column? I did see a post on page 9 that touched upon the subject but it assumed more knowledge than have at the moment.

    Can anyone please help me with this?

    The site is at http://www.eastcoastlacrosse.co.uk/modx/playlacrosse/index.php?q=index.html.html
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It depends on if you want the content to be the same for all pages, or if you want it to be different for every page, or if you want it to be different for different sections of the site.

      You would use chunks for static HTML content and text, snippets for dynamic menus, forms and any other dynamic or interactive content, and TVs for blocks of content specific to pages or groups of pages.

      Chunks can contain snippet and TVs, and TVs can contain chunks and snippets, so it can be very flexible.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4429
        • 429 Posts


        The content I want to add is search bar and some links (so html) and then my teams leagues tables (php using rest)

        At the moment I am happy for it to be present on every page at it is on my site -- www.playlacrosse.co.uk

        In my style sheet I have rightcontent setup and I have added <div id="rightcontent"> tags into my template.

        I do not however what this content hardcoded into the template.

        How do I go about this?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Create a chunk for each block of content. One for the search form, one for the links, and one for the league tables.

          Put the chunk tags in the template.

          Put the snippets or whatever you need in the chunks.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4429
            • 429 Posts
            Quote from: sottwell at Apr 11, 2008, 12:55 PM

            Create a chunk for each block of content. One for the search form, one for the links, and one for the league tables.

            Put the chunk tags in the template.

            Put the snippets or whatever you need in the chunks.

            Thanks! that works with my google search bar which is all HTML but what about for PHP?
              • 4429
              • 429 Posts
              A ha, PHP goes in a snippet.

              Here is my snippet below - what code do I need to put in my template to get this snippet to show?

              <div id="East2">
              
              <?	
              
              require_once('rest.inc');
              
              
              
              $xmlfile = 'east2-division.xml';  // local file name to store XML data
              
              $xmlurl = 'http://www.southlacrosse.org.uk/rest/tables/mens/East2'; // URL of data on South Lacrosse site
              
              
              
              // get the data from the South Lacrosse server, caching results for 2 hours
              
              $httpCache = new httpCache($xmlurl,$xmlfile);
              
              $httpCache->fetch();
              
              
              
              // parse XML data into arrays for easier processing
              
              if (!$httpCache->isError()) {
              
              	$parser = new simpleParser();
              
              	$xml = &$parser->parseString($httpCache->getXml());
              
              }
              
              
              
              if ($httpCache->isError()) {
              
              	echo '<p style="color: red;"><b>Error retrieving data : ' . $httpCache->getError()
              
              		. "</b></p>\n"; 
              
              } elseif (!$xml) {
              
              	echo '<p style="color: red;"><b>Error converting data : ' . $parser->getError()
              
              		. "</b></p>\n"; 
              
              } else {
              
              	// print heading for the division, and table heading for the league table for this division
              
              ?>
              
              	<h2><span><? echo $xml->division->{'division-name'}->cdata; ?></span></h2>
              
              		<table cellspacing="0" cellpadding="0">
              
              			<tr class="odd">
              
              				<td class="center">Pos</td>
              
              				<td class="team">Team</td>
              
              				<td class="center">Pld</td>
              
              				<td class="center">Pts</td>
              
              			</tr>
              
              <?
              
              	$pos = 0;
              
              	// Loop thru all the teams in the division, and print a table row for each team
              
              	foreach ($xml->division->team as $team) {
              
              		$played = $team->won + $team->drawn + $team->lost;
              
              		$pos++;
              
              		if ($pos % 2 == 1) {
              
              ?>
              
              <tr>
              
              <? } else { ?>
              
              <tr class="odd">
              
              <? } ?>
              
              <td class="center"><? echo $pos; ?></td>
              
              <td class="team"><? echo $team->{'team-name'}; ?></td>
              
              <td class="center"><? echo $played; ?></td>
              
              <td class="center"><? echo $team->points; ?></td>
              
              </tr>
              
              <?	} // end of teams loop ?>
              
              </table>
              
              <?
              
              // <p><small>Data provided by <a href="http://www.southlacrosse.org.uk/">southlacrosse.org.uk</a></small></p>
              
              } // end of else
              
              
              
              // finish off page
              
              ?>
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                That’s not a proper snippet. Snippets are ONLY php code.

                The code in a snippet is run through the PHP eval() function, so you need to gather all output into a variable, then when it’s all finished, return it as the return value of the function.

                In your case, you could set up the outer container in the chunk, then call the snippet with the snippet tags like [!SnippetName!] in the chunk where the rows of data are to be displayed. The snippet code would only generate the rows, and return the finished rowset.

                Error messages would also be assigned to a variable and returned (exiting the snippet at that point, just like any function).

                Here’s a very simple list I wrote some years ago; you can see how snippets work from it:
                /**** PopupList **************************
                *  Usage:
                *    [[PopupList?id=x]]
                *****************************************/
                if(!isset($id)) return; // quit if no id
                
                // get the pagetitle and content of the children 
                // of the given folder, sorted by their menuindex
                $children = $modx->getActiveChildren($id,'menuindex','ASC','pagetitle, content');
                if($children == false) return; // quit if no documents
                
                $list = '<ul id="popupList">'; // start the list
                
                foreach($children as $child) {
                  $list .= '<li><a href="#">'.$child['pagetitle'].'<span>'.$child['content'].'</span></a></li>'; // create the links and content blocks  
                }
                
                $list .= '</ul>'; // close the list
                return $list;  // and send it off.
                


                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 4429
                  • 429 Posts
                  oh dear, in that case I haven’t got a clue.

                  I was hoping I could just drop the code in there and that’s it.

                  I don’t know how php works i’m just handy with CTRL+X and CTRL+V

                  In drupal I was able to create a block then drop that code in. I’m sure the Modx way better (or just different) but just don’t understand it yet, though i’m willing to try.


                  EDIT - I’ve done what I wanted, but conerned that I had to change my permissions to 777 to get it to work :-( that’s nothing to do with modx though. Right next task ;-)