We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28854
    • 5 Posts
    Im a new user of MODx, and the way to approach the whole ’building a website’ process.

    I could use some advice on how to build the following.

    I have list of data in a database table. To simplyfy, lets assume it contains four columns, name and description, origin and size.

    I want to have two kinds of pages.

    One page to list all entries in this table, showing name and description in a list.

    [table]
    [tr][td]name1[/td][td]description1[/td][/tr]
    [tr][td]name2[/td][td]description2[/td][/tr]
    [tr][td]name3[/td][td]description3[/td][/tr]
    [/table]

    If you then click on a row in this table, you see another page, with detailed information about the row, displaying all the data layoutet in a nice way (template)

    I am not sure what the "right" way to do this in MODx. I know that all things can be done in a milion ways, but when you havent fully understood snippets, chunks, modules and plugins - its hard to start out, and I want to start out by doing this the MODx way, and learn from there.

    I also want to build the site with as little mix of layout and logic - to keep them seperated as much as I can.

    I can build the first page using a snippet that queries the database and, using a mix of PHP and html, outputs this. However, I have a feeling that this is not the best way to do it.

    Also, how would I build the links for the table, to load up the detailed page based on the ID of the row you click? Do I make a set of TV that each fetch the data I want. So that I have one TV that fetch the name, one for description, one for size etc? Doesnt that make alot of unnessesary queries to the database?

    I have used other CMS software where you can have your logic in one place, and the template html in another, and then just parse the html template, replacing the tags you have defined, I am sure that you basically do the same thing in MODx - only I havent figured out how to streamline this process?

    Do I really have to code alot of snippets/PHP in order to fecth things from the database and output them in a template?
      • 34017
      • 898 Posts
      This is how I would do it. Create 2 pages.
      1. Summary (example ID is 5)
      2. Details (example ID is 6)

      In your summary:

      Instead of echoing the text, parse a ’chunk template’ with
      foreach row {
        $my_chunk .= parsechunk('thechunk');
      
        //For the links:
        //Create a link (use modxapi) with id=6 and add &view_details=$row_id
      }
      
      setplaceholder -->mychunk //this is pseudocode
      

      In your summary, call your placeholder [+mychunk+]

      For the Details page
      Create your snippet to grab the &view_details, and do the parsechunk again.

      For a really good example of this, checkout ppp. It’s not supported anymore but is a really good example at using the modx api to retrieve info from a database, parse the info in a chunk, and return it. PPP is here - http://modxcms.com/forums/index.php/topic,8922.0.html


      Edit: This is very rough and just gives examples of how to setup the ’idea’. You’ll need to look into the api to see how to implement it correctly.
        Chuck the Trukk
        ProWebscape.com :: Nashville-WebDesign.com
        - - - - - - - -
        What are TV's? Here's some info below.
        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
        • 28854
        • 5 Posts
        Quote from: ProWebscape at Feb 07, 2008, 03:29 PM

        This is how I would do it. Create 2 pages.
        1. Summary (example ID is 5)
        2. Details (example ID is 6)

        In your summary:

        Instead of echoing the text, parse a ’chunk template’ with
        foreach row {
          $my_chunk .= parsechunk('thechunk');
        
          //For the links:
          //Create a link (use modxapi) with id=6 and add &view_details=$row_id
        }
        
        setplaceholder -->mychunk //this is pseudocode
        

        In your summary, call your placeholder [+mychunk+]

        For the Details page
        Create your snippet to grab the &view_details, and do the parsechunk again.

        For a really good example of this, checkout ppp. It’s not supported anymore but is a really good example at using the modx api to retrieve info from a database, parse the info in a chunk, and return it. PPP is here - http://modxcms.com/forums/index.php/topic,8922.0.html
        Thank you, this sounds alot like what I had thought I should do just didnt know you could parse a chunk to "fill in the blanks". I thought of a chunk as a piece of static html you could insert anywhere you wanted on a page.

        I’ll give it a go - it sounds like its quite easy to do (he said optimistically before reading any documentation about PPP and how to parse chunks) wink

        Quote from: ganeshXL at Feb 07, 2008, 09:12 PM

        Another general plan is to convert this extra-table to modx-documents (all in one folder). This makes sense if this data-set is just a one-time transfer from an old site to the new site (a typical scenario for a redesign).

        You could write a little php script that queries your table and inserts the fields into regular document-fields (title, description) and perhaps even template variables (origin, size). Create a special template for this first, so you can map the DB-fields to document fields. The docmanager class is handy for such things: http://modxcms.com/Docmanager-881.html

        If you go that route, you can easily use Ditto to create "preview" pages (incl. custom templates + automatic pagination) + also have full easy control on the "detailed page view".
        That would have been a way to do it, however, the website I am working on is a brand new site. Because it is brand new, I want to start out making it as MODx correct as I can. Also, this is just a hobby project and the usergroup is only a handful of people.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I thought of a chunk as a piece of static html you could insert anywhere you wanted on a page.
          That’s exactly what it is, even if you want it inserted repeatedly in the same page. Ditto and Wayfinder both use chunks as templates for their listings. The trick is the use of placeholders in the chunk to be replaced by the looping snippet at each iteration.
            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
            • 34017
            • 898 Posts
            If you’ve got time, you might want to look at using TVs and Ditto- but I feel this will be more of a learning curve for you.
              Chuck the Trukk
              ProWebscape.com :: Nashville-WebDesign.com
              - - - - - - - -
              What are TV's? Here's some info below.
              http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
              http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008