We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49561
    • 4 Posts
    Hi. Starting to understand MODX. Need to understand how to develop properly.

    1. There is a shop card resource with fields: phone, adress, description and logo (as image)
    The image is a resource.
    How to project better:
    1.1 phone, address, description and logo are child resouces
    1.2 phone, address, description and logo are TV-s, related with card resource

    Can logo (image) be a resource? If the logo is a TV - how to link it with the resource? I found information abouts its linking to
    a template, but dont understand how to link it with a resource. I need logo will be available in CMF tree (on the left side)
    as a child of the resource (desirable)

    2. How to built architecrure better?
    2.1 Resource -> child resources
    2.2 Resource -> TVs
    I mostly like second variant, the code will be easier. But probably this is inconvenient for CMF administrator.
    (need to move back and forth along the administration panel).

    3. TVs may be linked to resouces. Does it mean that TVs are resource childs?

    Thank you!
    Oleg, Russia
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      TVs are linked to Templates, and become available when editing a resource that uses that Template. Consider them as extra fields for a resource.

      Resources are usually equivalent to the pages the visitor will see, providing the content for that page, but they don't have to be. They can be used to store data other than the main content for the finished page.

      The Resource Tree roughly approximates the structure of the site, dynamic menus and listings of items like news articles or blog posts (or business cards) will be generated based on this Tree structure using the various listing snippets.

      There are several variations on TVs, for example MIGx creates a grid TV, where you can have multiple fields for the TV itself. For example, an image may need the path to the image, a title for the image, and a description of the image. A single page (resource) may need to display more than one of these images, for example a small gallery for a page about your dog, and again in another page about your cat. MIGx can provide a custom TV to provide these multiple images each with its own title and description, all in one TV.

      If you want to display business cards, you could do it in several different ways - this is MODX, that's what MODX does. There is never just one way to do something.

      It all depends on exactly what you want to do.

      You could have one resource for each business card, using a template just for these resources. A number of TVs would be associated with this "card" template to provide the extra fields for the "card" resource , so when editing each "card" resource you would get the TVs to fill out for that "card". Cards could be displayed individually as a separate web page, or in a gallery on a "Cards" page using a listing snippet like getResources with links to the individual card's page. The individual card page could have more information than what is shown in the gallery of cards.

      Another way would be to use MIGxDB, which is a custom TV that uses its own database tables for storage. You would have one "Cards" resource using a "Card" template, with the MIGxDB TV connected to the "Card" template. You would now have a grid in the "Card" resource's TV, with the ability to add new cards or edit existing cards in this grid. You can drag-and-drop the rows in the grid to order them. Each card in the grid would have multiple fields when being edited or created. To list the cards on the "Cards" page MIGx provides its own listing snippets. In this case, each card would not have its own page. The "Cards" page would have a gallery of cards built from its TV.



        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
        • 49562
        • 25 Posts
        Thanx,

        Continue a this way:

        Quote from: sottwell at Dec 18, 2014, 05:52 AM


        You could have one resource for each business card, using a template just for these resources. A number of TVs would be associated with this "card" template to provide the extra fields for the "card" resource , so when editing each "card" resource you would get the TVs to fill out for that "card". Cards could be displayed individually as a separate web page, or in a gallery on a "Cards" page using a listing snippet like getResources with links to the individual card's page. The individual card page could have more information than what is shown in the gallery of cards.


        So ok, I will describe the architecture I have developed.
        For example I have several cards. They are preview information of shopping mall lessees.
        The number of the cards depends on search results (people find lessees by goods, listed in description) . The fields of each card: phone, address, description and logo. Phone, address, description are child resources of the card resource. Card doesn't have a template, it is created by mixing php and html. I have no problems with phone, address, description.
        Сard resources belong to one template. Created TV variable also belong to that template. How will link definite resource with definite TV?

        The code:
        $counter = 0;
        
        for ($i = 1; $i <= $modx->getCount('modResource'); $i++)
        {
            $childIDs = $modx->getChildIds($i, 1, array('context' => 'web'));
            
            if ($childIDs[0] != null)  // если есть потомок
            {
                
                //echo '||| ',$childIDs[0]; 
                foreach ($childIDs as $childID)
                {
                    //echo $modx->getObject('modResource', $childID)->get('description');
                   
                    if ($modx->getObject('modResource', $childID)->get('pagetitle') == 'что продаётся'){
                        $whatIsSelling = $modx->getObject('modResource', $childID)->get('description');   
                    }
                    
                    if ($modx->getObject('modResource', $childID)->get('pagetitle') == 'контакты'){
                        $contacts = $modx->getObject('modResource', $childID)->get('description');            
                    }
        
                    if ($modx->getObject('modResource', $childID)->get('pagetitle') == 'график работы'){
                        $schedule = $modx->getObject('modResource', $childID)->get('description');            
                    }
                }  
                     
                echo
                '<div class="card">
        		<a href=""><img src="http://localhost/manager/templates/muravey/img/apelsin.gif" width="200px"></a>
        		<h2>Что продаётся</h2>
        		<p>',$whatIsSelling,'</p>
        		<h2 class="card_thin">Контакты</h2>
        		<h2 class="card_thin">График </h2>
        		<div style="clear: both;"></div>
        		<p class="card_thin">',$contacts,'</p>
        		<p class="card_thin">',$schedule,'</p>
        		<div style="clear: both;"></div>
        	</div>'; 
                
                
                $counter++;
                if ($counter == 4){
                    $counter = 0;
                    echo '
                    <div style="clear: both;"></div>
                    <hr><a href="" class="to_pictures">расположение магазинов в торговом центре</a>';
                }
                
            }
        }


          • 3749
          • 24,544 Posts
          TVs belong to a template, but they have a specific value for each resource. You don't need to do anything to get that to happen.

          After you create a TV, you can go to the Template Variables tab of any resource that uses a template connected to the TV and set the value of that TV for that particular resource. When that page is viewed, the TV can be displayed with a tag like this:

          [[*TvName]]


          So in your case:

          <img src="[[*Name_of_image_tv]]" width="200px;/> 
          
          
          <p class="card_thin">',[[*contacts]],'</p>
          <p class="card_thin">',[[*schedule]],'</p>
          


          If you need to deal with this in code, you can just do this:

          $doc = $modx->resource; /* reference to current resource */
          $contacts = $doc->getTVValue('contacts');


          BTW, I suspect that you will need to search and sort based on the card values. If so, and you have a lot of pages, TVs are not a good option. They will be slow.

          You'd be better off extending the modResource object with ClassExtender or on your own. That will give you extra resource fields in a custom table so you'll have very fast searching and sorting.
            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
            • 49561
            • 4 Posts

            BTW, I suspect that you will need to search and sort based on the card values. If so, and you have a lot of pages, TVs are not a good option. They will be slow.
            

            Exactly. Thank you.

            I will develop this branch to make my code perfect