We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44601
    • 18 Posts
    I just installed Revo V. 2.2.8-pl with Softaculous to my server, and it seems to be working perfectly. I love the way this framework is designed and I am hoping someone can point in the right direction to complete a function I need.

    I know HMTL/CSS pretty well, but I am new to JS, PHP, and Mysql.

    Basically I want to create a parent/child system of templates that can have hundreds or thousands of different pages each, but without a dedicated resource to each page. My ideal structure would be:

    Home
    About
    Content
    Content type 1 parent/child1/child2/child3/child4
    Content type 2 parent/child1/child2/child3/child4
    Content type 3 parent/child1/child2/child3/child4
    Content type 4 parent/child1/child2/child3/child4


    Each content type child would have its own unique template, and hundreds of possible pages per child type, but it would all include structured data.

    For an example lets use geography as a continent type,

    Earth/Continent/Area/Country/State/City

    I would create a template for each child here, but there are hundreds of countries. I would create one template called country, and use it to display data about whichever country link is called.

    I'm not looking for line by line code of how to do this, but if someone could point me in the right direction(s) I would be more than grateful.

    Thanks!


    This question has been answered by BobRay. See the first response.

      Be well!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You would do best to make use of the resource system. Each type of resource would have its own template. Use the various resource listing snippets (such as Wayfinder for nested listings).

      Leveraging the existing MODx elements and resources gives you a great deal of power and flexibility using existing functionality and add-ons without having to worry about coding anything yourself.

      When dealing with large groups of sub-items like you have, MIGXdb can be very useful, simply modifying the usage of existing elements. This would be a good example to study for your purposes http://rtfm.modx.com/display/ADDON/MIGXdb.Manage+Child-Resources+in+a+grid-TV+with+help+of+MIGXdb
        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
        • 3749
        • 24,544 Posts
        Welcome to MODX. smiley

        As with most things in MODX, there are *many* ways to do what you want.

        It's important to distinguish between Templates and a particular type of chunk, called a Tpl chunk which can serve as a mini Template. People often use the word "template" (incorrectly) to refer to Tpl chunks, so I'm not sure what you mean by templates.

        This pages might help you understand how MODX produces a page, which should provide handle on what you're trying to do:

        http://bobsguides.com/modx.html

        You will probably want some combination of Templates and Tpl chunks do to what you want, but I'm not sure on the mix. You could have a Template for each level (Earth, Continent, Country, etc.). On the other hand, you could conceivably use a single Template, and use a Tpl chunk for each level, with a snippet or output modifier to select which chunk or chunks get shown on a particular page.

        In the long run, if there is a lot of data (and it sounds like there will be), you'll probably want custom database tables to hold the data, one or more generic templates, and Resources containing Tpl chunk tags to show the view of the data. This will probably involve one or more custom snippets (PHP code) to inject the data into the page via placeholders in the Tpl chunks.






        [ed. note: BobRay last edited this post 13 years, 1 month ago.]
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You can use MIGXdb to ease the management of custom tables, if you decide that's what you need. MIGXdb can work with existing tables (such as the site_content table for resources) or with custom tables, for example this tutorial goes through creating a custom gallery http://rtfm.modx.com/display/ADDON/MIGXdb.Create+a+basic+gallery-management+from+scratch+with+MIGXdb
            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
            • 44601
            • 18 Posts
            Hey guys, thanks for the replies! Its taken me awhile to get back because.. well I spent way too much time in the ER.

            I am going to look through all of your suggestions and learn everything I can and if I have questions I will post here.

            Ohh and Bobray, Softaculous shows the version as 2.2.8-pl [ed. note: irro334 last edited this post 13 years, 2 months ago.]
              Be well!
              • 44601
              • 18 Posts
              Ok, so one thing I still dont quite grasp is how to make the website understand what data to pull.

              Say I create the template for countries.. how do I create the logic to pull a specific countries information?
                Be well!
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                A template is only the HTML structure that is applied to resources. MODx works primarily with Resources. All URLs are converted to resource IDs. While you can have a resource with no template, you cannot do anything with a template with no resources. Resources handle the content. Create a resource for each country. Every web page should be generated from a resource.
                  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
                • discuss.answer
                  • 3749
                  • 24,544 Posts
                  Your Template will have placeholder tags in it for the country's data, how they get replaced with the actual data depends on your strategy.

                  If the data is in Template Variables, each page will have a value for that variable and you can just use TV tags in the Template.

                  If the data is in a chunk, you can use a chunk tag.

                  If you're up to the coding, one method would be to store the data in a custom DB table where each row is a country. Then you'd create a chunk with placeholder tags for each field and write a snippet to get the data from the DB and replace the placeholders. If the DB table is set up for xPDO, the code could be almost as simple as the following code.

                  This assumes that you've set up the table as an xPDO object called 'modCountry', each row has a country_name field , the pagetitle of the current page is the country, and you have a Tpl chunk called "CountryDataView" that contains the placeholders:


                  <?php
                  
                  $title = $this->modx->resource->get('pagetitle');
                  
                  $country = $modx->getObject('modCountry', array('country_name' => $title));
                  
                  if ($country) {
                      $output =  $modx->getChunk('CountryDataView', $country->toArray());
                  } else {
                      $output = 'Country not found';
                  }
                  
                  return $output;
                  


                  A slightly different (better) way to go would be to have a single page that displays the country data and put a $_GET parameter called 'country' in the link to the page to specify the country. The method would be exactly the same but the first line would change to:

                  $title = $_GET['country']


                  The link would look something like this:


                  <a href="mysite.com/view-country?country=Germany>Germany</a>







                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 44601
                    • 18 Posts
                    Thank you for the replies guys! Sorry I'm slow to respond, I have a very rare medical condition and I've been pretty sick lately.

                    I will be busy all week but I will try to figure this out this weekend.

                    And I don't want to create a new resource for every page, I'd end up with millions of them and never be able to load the admin menu, but thank you for the advice.
                      Be well!
                      • 3749
                      • 24,544 Posts
                      Quote from: irro334 at Aug 13, 2013, 10:39 PM

                      And I don't want to create a new resource for every page, I'd end up with millions of them and never be able to load the admin menu, but thank you for the advice.


                      Quote from: BobRay
                      A slightly different (better) way to go would be to have * a single page * that displays the country data and put a $_GET parameter called 'country' in the link to the page to specify the country.

                      Hope you're feeling better. smiley

                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting