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

    Please forgive me if this question is too dumb for words . . . I’m very new to modx and have an elementary question:

    I want a child document to appear in a parent folder like this:

    http://www.mysite.com/about/index.html

    If I type the above, I get the file as expected. However, if I type the following:

    http://www.mysite.com/about/

    I get the template associated with the folder "about" which in this case happens to be blank (couldn’t select it to no template as I thought I might be able to). Should that be the case? Is there a way to get the index.html file to show up just by typing in the folder name, as above? Also, in the above example, the folder "about" has an ID of 5. I can get to the folder through the following also:

    http://www.mysite.com/5.html

    Should that be the case too? I don’t get how a folder can be a file?

    Finally, some of my settings:

    Use Friendly URLS - YES
    Suffix - .html
    Use Friendly Alias - YES
    Use Frindly Alias Paths - YES
    Allow Duplicate Alias - YES (becuase I use index for the site start page and plan to index for each start page inside each folder)

    Can anyone help?

      • 18397
      • 3,250 Posts
      Remember that MODx documents are just database entries and are not "real" folders or files at all.

      You should be able to set a template for a folder.
        • 32241
        • 1,495 Posts
        Or you can use redirect on the folder by creating a snippet with
        $modx->sendRedirect($modx->makeUrl(5));


        More information on this, http://modxcms.com/forums/index.php/topic,2054.0.html

        I haven’t tested the script yet, hope it works for you
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
        • Quote from: myan24 at Feb 23, 2006, 01:25 AM

          I want a child document to appear in a parent folder like this:

          http://www.mysite.com/about/index.html

          If I type the above, I get the file as expected. However, if I type the following:

          http://www.mysite.com/about/

          I get the template associated with the folder "about" which in this case happens to be blank (couldn’t select it to no template as I thought I might be able to). Should that be the case? Is there a way to get the index.html file to show up just by typing in the folder name, as above? Also, in the above example, the folder "about" has an ID of 5. I can get to the folder through the following also:

          http://www.mysite.com/5.html

          Should that be the case too? I don’t get how a folder can be a file?
          Just think of folders as documents that can have children. They can also contain content, perhaps a summary of all the things in it or whatever else might be appropriate, accessible via several approaches (as you noticed).

          To emulate a web server which is configured to look for an index.html page when the folder URL is provided, you can easily create a template to assign to your folders with just the following content:
          <html><body>[!FolderIndex!]</body></html>

          Then code a simple snippet called FolderIndex that looks for a child doc with the alias of index, something like this:
          $children= $modx->getDocumentChildren($this->documentIdentifier, 1, 0, "id", "alias='index'", "", "", "1");
          if (!isset ($children[0]['id']) || !$indexPageId= $children[0]['id']) {
          	return "<p>Directory browsing not allowed!</p>";
          }
          $modx->sendRedirect($modx->makeUrl($children[0]['id']));
          


          That would emulate typical Apache directory behavior, and you can customize that however you want from there. There are probably many other ways to approach this, for instance a plugin that checks to see if the requested document is a folder type (i.e. has children), and decides what to do via any registered events, but I just wanted to give you an idea of how you can approach this in a MODx way.

          There are other solutions similar to this in these forums as well, such as at this topic: http://modxcms.com/forums/index.php/topic,1394.0.html
            • 32241
            • 1,495 Posts
            Thanks Jason for the extensive explanation.
            My opinion will be to use snippet, because sometimes having a different content inside a folder will be necessary, for example in blog or news page, where you need the folder to display all the available child pages. If we set that up as a plugin, basically it will affect all the folders, but if we set it as a snippet, all we need to do just drop the snippet on the right page, and that’s all, you’re up and running.

            Here is another quick little snippet that might serve your need as well.

            // Create a new snippet and name it RedirectPage
            // Call it using [!RedirectPage? &docid=`5`!]
            // docid will be the page id number for your redirection
            if(isset($docid) && $docid != $modx->documentIdentifier)
              $modx->sendRedirect($modx->makeUrl($docid));
            
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 20751
              • 122 Posts
              Hey Guys!

              Just got in! Thanks so much for all your input . . . I’m going to try these suggestions out later tonight! You guys rock!!!

              grin
                • 20751
                • 122 Posts
                Quote from: Djamoer at Feb 23, 2006, 02:46 PM

                Thanks Jason for the extensive explanation.
                My opinion will be to use snippet, because sometimes having a different content inside a folder will be necessary, for example in blog or news page, where you need the folder to display all the available child pages. If we set that up as a plugin, basically it will affect all the folders, but if we set it as a snippet, all we need to do just drop the snippet on the right page, and that’s all, you’re up and running.

                Here is another quick little snippet that might serve your need as well.

                // Create a new snippet and name it RedirectPage
                // Call it using [!RedirectPage? &docid=`5`!]
                // docid will be the page id number for your redirection
                if(isset($docid) && $docid != $modx->documentIdentifier)
                  $modx->sendRedirect($modx->makeUrl($docid));
                


                Thanks for this! I’m able to get it to work if I make the call inside a folder template, but can’t get it to work when I drop the snippet into the folder document i.e. the parent document. Is it possible to just drop the snippet into the parent document? Otherwise I’ll have to create separate parent document templates for each parent document.

                Hope that made sense!

                Thanks!
                  • 20751
                  • 122 Posts
                  OK. I think I’ve figured out how to apply this logic to a folder template using a bit of code I found here:

                  http://modxcms.com/forums/index.php/topic,1394.msg9207.html#msg9207

                  thanks opengeek . . . and by using a bit from Djamoer. Here’s what I have . . . seems to work!

                  if(isset($docid) && $docid != $modx->documentIdentifier)
                  $id=$modx->documentIdentifier;
                  $children=$modx->getActiveChildren($id,'menuindex','ASC');
                  if (!$children===false)
                  {
                  $firstChild = $children[0];
                  $firstChildUrl = $modx->makeUrl($firstChild['id']);
                  }
                  else
                  {
                  $firstChildUrl = $modx->makeUrl($modx->config['site_start']);
                  }
                  return $modx->sendRedirect($firstChildUrl);



                  Just have to make sure that the document to redirect to is the first document created under the parent document (i.e. the first child document).