We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36613
    • 328 Posts
    I follow this tutorial:
    http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/creating-a-multi-select-box-for-related-pages-in-your-template

    for create a list of related page, but i want have the specific parent for diffirent context. This is my solution snippets:

    <?php
    $document = $modx->getObject('modResource',$modx->resource->get("id"));;
    $key = $document->get('context_key');
    $ctx = $modx->getContext($key);
    
    $parent = $modx->getOption('parent',$scriptProperties,$ctx->getOption('myparentdi_id'));
    $parentObj = $modx->getObject('modResource',$parent);
    if (!($parentObj instanceof modResource)) { return ''; }
    $resArray = $parentObj->getMany('Children');
    $resources = array();
    foreach($resArray as $res) {
      if ($res instanceof modResource) {
        $resources[] = $res->get('pagetitle') . '==' . $res->get('id');
      }
    }
    $out = implode("||",$resources);
    return $out;


    I think it can help you.
      • 36613
      • 328 Posts
      I follow this tutorial:
      http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/creating-a-multi-select-box-for-related-pages-in-your-template

      for create a list of related page, but i want have the specific parent for diffirent context. This is my solution snippets:

      <?php
      $document = $modx->getObject('modResource',$modx->resource->get("id"));;
      $key = $document->get('context_key');
      $ctx = $modx->getContext($key);
      
      $parent = $modx->getOption('parent',$scriptProperties,$ctx->getOption('myparentdi_id'));
      $parentObj = $modx->getObject('modResource',$parent);
      if (!($parentObj instanceof modResource)) { return ''; }
      $resArray = $parentObj->getMany('Children');
      $resources = array();
      foreach($resArray as $res) {
        if ($res instanceof modResource) {
          $resources[] = $res->get('pagetitle') . '==' . $res->get('id');
        }
      }
      $out = implode("||",$resources);
      return $out;


      I think it can help you.
        • 7604
        • 4 Posts
        This is a plugin free solution that might help if I am understanding the problem correctly.
        I believe I am doing the same thing currently, and each time I do this task I always forget the built in features that make what you are talking about very easy.

        So in my case I have a bunch of sites, each one has a gallery section. Where they build a gallery using a page/template that then inserts a gallery into the main gallery page. But I also want them to be able to insert that gallery into the relevant service page as that is where most of the traffic is and that is where it will support lead conversion the best.

        So What I did was

        1. Create A TV
        2. Input Type Resource List
        3. Set the depth as tight as possible(especially for single contexts, because PDO will blow up break the page because the query will be way too big)
        4. Select Yes in Limit to Related Context(this is what specifically solves your problem)
        5. Next I set the where conditions to the below(this is the other part of the solution, as my guess would be that your module pages have specific templates, and this restricts that to just to pages using that template(s))
        6. Finally I set the limit to set a tight limit of results(again for PDO so it keeps it from looping out of control)
        7. Done

        Where conditions
        [{"template:=":"1"}]


        The default is to show all pages regardless of published status. In another use case I wanted to not have the user be able to select unpublished pages so I used the below to only show users items that were published.

        [{"template:=":"2","AND:published:=":"1"}]


        Now just for the folks that are trying to do something like this and haven't figured out the rest of it.

        To get it into my page I use a quick getResources call like
        [[*gallerySelector:notempty=`[[!getResources?
        				&resources=`[[*gallerySelector]]`
        				&depth=`0`
        				&limit=`1`
        				&pageVarKey=`page`
        				&includeTVs=`1`
        				&includeContent=`1`
        				&sortby=`menuindex`
        				&sortdir=`ASC`
        				&tpl=`GalleryTPL`
        			]]`]]
        

        This cool in a couple of different ways. First I check to see that TV was used in the page. Otherwise it will spit out a bunch of code even if they didn't want a gallery in the page. Next it uses the template in get resources to create the gallery and I am done. I also have a the javascript and the CSS for the gallery sitting in another TV notempty call so the page only loads it if we need it. This saves on page load time for SEO and it keeps the general weight of the load on the server down, so you are not using excess resources that you don't need.

        Hope this helps! [ed. note: djverbal last edited this post 12 years, 10 months ago.]
          • 4172
          • 5,888 Posts
          Keep in mind, that this will execute getResources, also when gallerySelector is empty.
          There is a better solution, which would look like that:

          [[[[*gallerySelector:notempty=`!getResources?
                          &resources=`[[*gallerySelector]]`
                          &depth=`0`
                          &limit=`1`
                          &pageVarKey=`page`
                          &includeTVs=`1`
                          &includeContent=`1`
                          &sortby=`menuindex`
                          &sortdir=`ASC`
                          &tpl=`GalleryTPL`
                      `]]]]


          The output-filter checks, if gallerySelector is not empty and outputs the snippet-tag.
          After that, the output of the output-filter gets parsed.


            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!