We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48244
    • 23 Posts
    I'm a relative newbie, but love MODx. My page is a list of items, that will vary in length. It may have 3 items, it may have 20. Each item will have a photo and aadition info. A Product list in essence. Here is the basic Chun that includes all variables for one line item:

    <section class="itemRow">			
    <div class="container">
    	<div class="row ">
    		<div class="col-md-4">
    			<a class="img-thumbnail lightbox"	href="[[*01-used-link]]" data-plugin-options='{"type":"image"}'>
    				[[*01-used-image-th]]
    					<span class="zoom">
    					<i class="icon icon-16 icon-white-shadowed icon-search"></i>
    					</span>
    			</a>
    		</div>
    
    		<div class="col-md-8">
    			<h2 class="tinos short">[[*01-used-itemname]]</h2>
    			<h5>[[*01-used-price]]</h4>
    			<ul>
    				<li>Name: [[*01-used-contact-name]]</li>
    				<li>Company: [[*01-used-contact-company]]</li>
    				<li>Location: [[*01-used-contact-location]]</li>
    				<li>Phone: [[*01-used-contact-phone]]</li>
    				<li>email: [[*01-used-contact-email]]</li>
    			</ul>
    		</div>
    		</div>
    	</div>
    </section>



    What is the best way to handle this?
      • 4172
      • 5,888 Posts
      There are many ways.

      The way, which does work out of the box, is to use sub-resources for each item and list them with getResources (or, what I prefer, pdoResources)

      If this items doesn't need to be searchable on other places in your site and if this are not to much items you could thing about using a MIGX-TV to store all items as one json-string into one TV and use the included getImageList - snippet to list them.

      If you want to have them in its own custom-table, you could create a Custom-Manager-Page (for example with help of MIGXdb) or a MIGXdb - TV to manage them.
      Then you can use for example migxLoopCollection for listing them.


      Which way to choose depends on the type of datas, how many items this would be, if they need to be searchable, sortable and if you want to show them on many places on your page or only at a single place.

      So, we would need a bit more information of the kind of datas and what you have in mind.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 48244
        • 23 Posts
        Thank you for the reply. I've attached a screen shot of part of the page I'm talking about. Here is the section that is repeated for each item for sale. In this image I show items for sale with information like Name, price, location, phone, etc. The code in my initial posting is the exact code for the first item.

        Currently each item has it's own TV's assigned: 01-used-link for first item on sale, 02-used-link for second item on sale, 03-used-link for third item on sale, etc. This works, but the page will not grow as products are added unless I create additional TVs. Clunky...

        Since I'm a MODx newbie, and not a hard-core developer, I'm looking for a solution that is easily deployed given my limited experience.

        Thank you! [ed. note: markus5010 last edited this post 9 years, 9 months ago.]
          • 3749
          • 24,544 Posts
          I think the way you're doing it will be very slow, and will get slower each time you add a new product. As you say, it's also kind of tedious to work with.

          An easy step up would be to have a resource for each product. That way, you only need one set of the TVs, since their values will be specific to each resource/product.

          Then, your master page can show all products with getResources, naming your chunk above in the &tpl property of the getResources snippet tag.

          This will still be slow, but will be much faster and easier than what you're doing.

          For more speed, you could use MIGX as Bruno17 suggests, which would put all the TV data into a single TV, or you could use ClassExtender to extend the modResource object which would eliminate the TVs altogether. (See this link for why using TVs is slow: http://bobsguides.com/blog.html/2014/06/02/why-extend-modresource/.)

          If MIGX and ClassExtender are too technical for you, another fairly easy way to get what you want (once you have a resource for every product with your existing TVs) would be this method: http://bobsguides.com/blog.html/2014/07/29/speed-up-page-loads-with-a-plugin/. That would write a fully processed version of your chunk into each Resource's introtext (summary) field as you save it. This would give you very fast page loads and is easy to work with once you get it set up.
            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
            • 48244
            • 23 Posts
            Ok, I'll use getResources. I've added this to the page template:

            [[!getResources? &parents=`68` &tpl=`useditemsection` &includeTVs=`1` &processTVs=`1`]]
            

            Here is my (chunk) tpl named "useditemsection"

            <section class="itemRow">			
            <div class="container">
            	<div class="row ">
            		<div class="col-md-4">
            			<a class="img-thumbnail lightbox" href="[[+tv.used-link]]" data-plugin-options='{"type":"image"}'>
            				[[+tv.used-image-th]]
            					<span class="zoom">
            					<i class="icon icon-16 icon-white-shadowed icon-search"></i>
            					</span>
            			</a>
            		</div>
            
            		<div class="col-md-8">
            			<h2 class="tinos short">[[+tv.used-itemname]]</h2>
            			<h5>[[+tv.used-price]]</h4>
            			<ul>
            				<li>Name: [[+tv.used-contact-name]]</li>
            				<li>Company: [[+tv.used-contact-company]]</li>
            				<li>Location: [[+tv.used-contact-location]]</li>
            				<li>Phone: [[+tv.used-contact-phone]]</li>
            				<li>email: [[+tv.used-contact-email]]</li>
            			</ul>
            		</div>
            		</div>
            	</div>
            </section>


            I've created resources under "68" for each product for sale.
            *** Not sure about this: Each of those resources was assigned a new page template that only included the TVs in the chunk "useditemsection".

            I also assign a page template to each resource (item for sale). Is that correct? Does it need a template? If not, how do I assign the TVs ( in "useditemsection") to them?


            Sorry for the stupid questions. Just trying to learn a new development platform. Thanks again, [ed. note: markus5010 last edited this post 9 years, 9 months ago.]
              • 3749
              • 24,544 Posts
              No, the pages should all have the same Template, with those TVs attached to it. It should be designed to show a nice view of one product. You can add extra details about the product (not visible in the getResources display) in the Resource Content field (the big text area) and put [[*content]] in the Template for those pages.

              In the Tpl chunk you show above, you can make the image (or anything else) a link to the resource page for that product with something like this:

              <a href="[[~[[+id]]]]">Whatever</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
                • 48244
                • 23 Posts
                Thanks BobRay.

                I did assign the same template to each the items (4). But the TVs assigned to each are not showing up. In my Tpl chunk, are the TVs syntax correct? Should they correspond to the TVs in the template the item pass use?
                  • 48244
                  • 23 Posts
                  I got it to work. Thank you. I added &tvPrefix=``.

                  Where does the getPage go? below the get Resources on the template page?
                    • 4172
                    • 5,888 Posts
                    what you have (the getResources - call and the tpl-chunk)

                    is looking good and should work.

                    are these resources published and not hidden from menu?

                    if they are hidden from menu, try to use the property

                    &showHidden=`1`
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 4172
                      • 5,888 Posts
                      if you want to have pagination you would just wrap your getResources-call in getPage, like that:

                      [[!getPage? 
                        &element=`getResources` 
                        &parents=`68` 
                        &tpl=`useditemsection` 
                        &includeTVs=`1` 
                        &processTVs=`1`
                        &tvPrefix=``
                      ]]
                      <div class="pageNav">[[!+page.nav]]</div>


                      this would replace your getResources-call
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!