We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7575
    • 85 Posts
    Hi

    I have a TV "categorie" that holds the id of categories in my external database.
    my site tree has a branch with all my categories.

    Now I would like to show the title of all parent-documents as links and all children-documents as link.

    when the TV is 0 that means that it is not a category.

    showparents:
    <?php
    $currentResource = $modx->resource;
    $tv = $modx->getObject('modTemplateVar',array('name'=>'categorie'));
    //zet $kindervan op de juiste id en nul als er geen id is
    if ($categorie<>0){
    	$parentResource = $currentResource->getOne('Parent');
    	if (isset($parentResource)){
    		if ($tv->renderOutput($parentResource->get('id'))<>0){
    			$parentsparentResource = $parentResource->getOne('Parent');
    			if (isset($parentsparentResource)){
    				if ($tv->renderOutput($parentsparentResource->get('id'))<>0){
    					$kinderenvan=$parentsparentResource->get('id');
    				}
    				else{$kinderenvan=3;}
    			}
    			else{$kinderenvan=3;}
    		}
    		else{$kinderenvan=3;}
    	}
    	else{$kinderenvan=3;}
    }
    else{$kinderenvan=3;}
    
    $criteria = $modx->newQuery('modResource');
    $criteria->where(array(
       'parent' => $kinderenvan,
    ));
    $criteria->sortby('pagetitle','ASC');
    $parents = $modx->resource->getMany('Children',$criteria);
    foreach ($parents as $parent){
    	 echo "<a href=\"index.php?id=".$parent->get('id')."\">".$parent->get('pagetitle')."</a> ";
    }
    ?>


    showchildren
    <?php
    $currentResource = $modx->resource;
    
    if ($categorie<>0){
    	$criteria = $modx->newQuery('modResource');
    	$criteria->where(array(
    	   'parent' => $currentResource->get('id'),
    	));
    	echo $currentResource->get('id');
    	$criteria->sortby('pagetitle','ASC');
    	$children = $modx->resource->getMany('Children',$criteria);
    	foreach ($children as $child){
    		 echo "<a href=\"index.php?id=".$child->get('id')."\">".$child->get('pagetitle')."</a> ";
    	}
    }
    ?>


    you can see this in action on my test site (don’t look at the "looks")
    http://www.fabber.be/modx-2.0.0-rc-1


    left top is parents, right top is children

    document tree:with document id
    Lijst 3
    *sport 4
    **volleybal 5
    **hockey 8
    *cultuur 6
    **muziek 7

    when I navigate to "sport" it should show the top level of categories on the left (sport - cultuur)
    and the sub categories of sport on the right (volleybal - muziek)

    But instead is shows (sport - cultuur) on both places!
    while debugging I added the document ID of the parent of the shown categoies in front of the categories wich gives:
    3 sport - cultuur
    and
    4 sport - cultuur
    So the snippets get the right id’s but show the wrong children?
    the code is the same so I don’t see the problem?

      www.tornooi.net online database for (sport) events in dutch.
      To be redesigned, rewritten to modx with multiple languages...
      ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
      • 22303 MODX Staff
      • 10,725 Posts
      I would upgrade to RC2 or the most recent SVN revision. If you are still having problems afterwards, we’ll dig in.
        • 7575
        • 85 Posts
        AM I correct that I should follow "Upgrading MODx Revolution 2.0.0"
        and not "Upgrading to Revolution 2.0.0-rc-2"

        As I am not a develloper?

        something completely different:
        how com there are no specific urls to pages on the modx site? it only shows http://www.modx-cms.com/
        I find that frustrating.

        greetings
          www.tornooi.net online database for (sport) events in dutch.
          To be redesigned, rewritten to modx with multiple languages...
          ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
          • 7575
          • 85 Posts
          ok, I upgraded to MODx Revolution 2.0.0-rc-2 rev6923
          but the problem stays
          you can see it at http://www.fabber.be/modx-2.0.0-rc-1
          don’t worry about the old url (if I change the foldername I can’t get to the manager anymore)
            www.tornooi.net online database for (sport) events in dutch.
            To be redesigned, rewritten to modx with multiple languages...
            ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: djemmers at Jun 22, 2010, 01:37 AM

            AM I correct that I should follow "Upgrading MODx Revolution 2.0.0"
            and not "Upgrading to Revolution 2.0.0-rc-2"

            As I am not a develloper?
            If you are upgrading from RC1 to RC2, then you need to follow Upgrading to Revolution 2.0.0-rc-2.

            Quote from: djemmers at Jun 22, 2010, 01:37 AM

            something completely different:
            how com there are no specific urls to pages on the modx site? it only shows http://www.modx-cms.com/
            I find that frustrating.
            I don’t know what you are talking about here; that is not our site.

            Quote from: djemmers at Jun 22, 2010, 03:03 AM

            ok, I upgraded to MODx Revolution 2.0.0-rc-2 rev6923
            but the problem stays
            you can see it at http://www.fabber.be/modx-2.0.0-rc-1
            don’t worry about the old url (if I change the foldername I can’t get to the manager anymore)
            First, you should return content, not echo it, in snippets.

            Still seems like something else is being cached. You can look at the cached files to get a clue what might be happening. See core/cache/web/resources/{id}.cache.php
              • 7575
              • 85 Posts
              tnx for the reply opengeek.

              as for the modx-cms.com thingie, the site modx-cms exists (and is the same as modxcms.com) but now all links on that page reffer to modxcms.com .
              that was not the case when I posted the message.

              about my snippets.

              below is from the page:http://www.fabber.be/modx-2.0.0-rc-1/index.php?id=5
              with as parents cultuur & sport
              and as children beachvollyebal & wallybal/

              I looked in the cache.
              when I call my snippets like:
              [[showparents? &categorie=`[[*categorie]]`]]
              [[showchildren? &categorie=`[[*categorie]]`]]
              then I see in the id.cache files:

              in _content:
              <div id="links">3<a href="index.php?id=6">cultuur</a> <a href="index.php?id=4">sport</a> </div>
               <div id="rechts">5<a href="index.php?id=6">cultuur</a> <a href="index.php?id=4">sport</a> </div>

              and
              'elementCache' => 
                array (
                  '[[*pagetitle]]' => 'volleybal',
                  '[[*categorie]]' => '2',
                  '[[showparents? &categorie=`2`]]' => '3<a href="index.php?id=6">cultuur</a> <a href="index.php?id=4">sport</a> ',
                  '[[showchildren? &categorie=`2`]]' => '5<a href="index.php?id=6">cultuur</a> <a href="index.php?id=4">sport</a> ',
                )

              the 3 and 5 are correct but after 5 there should be something else . (id’s 9 and 10 should be there)

              when I call like
              [[!showparents? &categorie=`[[*categorie]]`!]]
              [[!showchildren? &categorie=`[[*categorie]]`!]]
              then is see:
              in _content
              <div id="links">[[!showparents? &categorie=`2`!]]</div>
              <div id="rechts">[[!showchildren? &categorie=`2`!]]</div>

              and nothing about them in elementcache output same as above...
              wich seems logical as now nothing is cached of the snippet...

              I don’t see where the problem might be.
              The id from the document of wich the snippets should show te children is shown correctly but not the children of the document.

              I have no idea how the cache will help me?

              Should I reïnstall rc-2 from scratch or is there another place I can look ?

              to be complete: here are the snipptes without echo and with return smiley
              showparents
              <?php
              $currentResource = $modx->resource;
              $tv = $modx->getObject('modTemplateVar',array('name'=>'categorie'));
              //zet $kindervan op de juiste id en nul als er geen id is
              if ($categorie<>0){
              	$parentResource = $currentResource->getOne('Parent');
              	if (isset($parentResource)){
              		if ($tv->renderOutput($parentResource->get('id'))<>0){
              			$parentsparentResource = $parentResource->getOne('Parent');
              			if (isset($parentsparentResource)){
              				if ($tv->renderOutput($parentsparentResource->get('id'))<>0){
              					$kinderenvan=$parentsparentResource->get('id');
              				}
              				else{$kinderenvan=3;}
              			}
              			else{$kinderenvan=3;}
              		}
              		else{$kinderenvan=3;}
              	}
              	else{$kinderenvan=3;}
              }
              else{$kinderenvan=3;}
              
              $criteria = $modx->newQuery('modResource');
              $criteria->where(array(
                 'parent' => $kinderenvan,
              ));
              $showparents=$kinderenvan;
              $criteria->sortby('pagetitle','ASC');
              $parents = $modx->resource->getMany('Children',$criteria);
              foreach ($parents as $parent){
              	 $showparents=$showparents."<a href=\"index.php?id=".$parent->get('id')."\">".$parent->get('pagetitle')."</a> ";
              }
              return $showparents;
              ?>


              showchildren
              <?php
              $currentResource = $modx->resource;
              
              if ($categorie<>0){
              	$criterias = $modx->newQuery('modResource');
              	$criterias->where(array(
              	   'parent' => $currentResource->get('id'),
              	));
              	$showchildren=$currentResource->get('id');
              	$criterias->sortby('pagetitle','ASC');
              	$children = $modx->resource->getMany('Children',$criterias);
              	foreach ($children as $child){
              //print_r($child);
              		 $showchildren=$showchildren."<a href=\"index.php?id=".$child->get('id')."\">".$child->get('pagetitle')."</a> ";
              	}
              return $showchildren;
              }
              ?>


                www.tornooi.net online database for (sport) events in dutch.
                To be redesigned, rewritten to modx with multiple languages...
                ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: djemmers at Jun 23, 2010, 02:19 AM

                as for the modx-cms.com thingie, the site modx-cms exists (and is the same as modxcms.com) but now all links on that page reffer to modxcms.com .
                that was not the case when I posted the message.
                Correct; whomever runs that site was using a frameset to load our site. We implemented a frame-buster yesterday after your post. wink

                As for calling snippets uncached, you should not have an ! at the end:

                <div id="links">[[!showparents? &categorie=`2`]]</div>
                <div id="rechts">[[!showchildren? &categorie=`2`]]</div>

                  • 7575
                  • 85 Posts
                  Quote from: OpenGeek at Jun 23, 2010, 11:24 AM

                  Correct; whomever runs that site was using a frameset to load our site. We implemented a frame-buster yesterday after your post. wink

                  glad that that is solved ;-)

                  as for my cache problems,
                  having the snippets run cached or not doesn’t solve my problem...
                    www.tornooi.net online database for (sport) events in dutch.
                    To be redesigned, rewritten to modx with multiple languages...
                    ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    If you can better focus and isolate the specific code you are having a problem with then maybe I can assist better.
                      • 7575
                      • 85 Posts
                      Ok, I’ll try:

                      I made 2 short snippets.
                      I call them like this:
                      <div id="links">[[first]]</div>
                      <div id="rechts">[[last]]</div>

                      One is shown on the left en one on the right. see http://www.fabber.be/modx-2.0.0-rc-1/index.php?id=5
                      left:
                      <?php
                      $firstcriteria = $modx->newQuery('modResource');
                      	$firstcriteria->where(array(
                      	   'parent' => '3',
                      	));
                      	$firstcriteria->sortby('pagetitle','ASC');
                      	$firstlijst = $modx->resource->getMany('Children',$firstcriteria);
                      $first="parents:";
                      	foreach ($firstlijst as $firsteen){
                      		 $first=$first."<a href=\"index.php?id=".$firsteen->get('id')."\">".$firsteen->get('pagetitle')."</a> ";
                      	}
                      return $first;
                      ?>

                      should show the parents of document 5:
                      parents: cultuur sport (wich is correct)

                      and right:
                      <?php
                      $lastcriteria = $modx->newQuery('modResource');	
                      $lastcriteria->where(array('parent' => '5',));
                      $lastcriteria->sortby('pagetitle','ASC');	
                      $lastlijst = $modx->resource->getMany('Children',$lastcriteria);
                      $last="children:";
                      	foreach ($lastlijst as $lasteen){
                      		 $last=$last."<a href=\"index.php?id=".$lasteen->get('id')."\">".$lasteen->get('pagetitle')."</a> ";
                      	}
                      return $last;
                      ?>

                      should show the children of document 5 :
                      children: beachvolleybal wallybal
                      but instead it shows the wrong names:
                      children: cultuur sport.

                      Notice that they both are exactly the same except for the names of the variables and the ID number in the criteria.

                      If I change the order of the snippets:
                      I show the children on the left and the parents on the right I get 2 times the children: beachvolleybal and wallybal.
                      children: beachvolleybal wallybal on the lef and
                      parents: beachvolleybal wallybal on the right.


                      In the cache files I just see the output as described before.
                      What do you suggest I do? What info do you need ?
                      Should I try a complete new install ?

                      to be complete, I included a printscreen of the document tree...
                        www.tornooi.net online database for (sport) events in dutch.
                        To be redesigned, rewritten to modx with multiple languages...
                        ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.