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

    I’m quite new to the modx thing, so i may not get the syntax right straight away...

    I have a portfolio page where the user selects one project from many. This page is generated partly by a getResources call. And it works. The div id, which is my project id, gets passed via php url to the next page (js:location.href="http://fuchs.raumanstalt.ch/index.php?id=14&P=113). This project number (P=113) gets picked up by a snippet getProjektnummer (via php echo) to write it into the getresources call:

    [[!getResources? &parents=`[[~2]] &processTVs=`1` &includeTVs=`1` &where=`{"tv.Projektnummer:LIKE":"[[getProjektnummer]]"}` &tpl=`infoTpl`]] 


    so now i have to match the projectnumber with the one resource which has a tv (Projektnummer) with the same value.

    how do i get this one resource? maybe getresources isn’t the right way. i’ve tried &tvfilters, too, but no success. :’(

    Please, help me, guys!

      • 4172
      • 5,888 Posts
      hmm.. I’m not very clear what you are trying todo.

      where do you have your projects?
      Are they modx-resources or in custom-table?
      can you also show us your code for getProjektnummer?
      what do get when you put [[getProjektnummer]] outside of the getresources-call?
      did you try uncached snippet-call [[!getProjektnummer]]?

      can you also show your other getresources-call and its tpl-code?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 12990
        • 6 Posts
        trying to clarify..

        first i have this page, where different resources get pulled into the site with cardTpl chunk:
        http://fuchs.raumanstalt.ch/index.php?id=2

        this is the call:
        [[!getResources? &parents`[[*id]]` &processTVs=`1` &tpl=`cardTpl` &includeTVs=`1`]]


        the Tpl is:
        <div class="entry" id="[[+tv.Projektnummer]]" >
        
                  <div class="wrapper">
                    <div class="entry_title">
                      <p>[[+tv.projectName]]</p>
                    </div>
                    <div class="entry_image"> [[+tv.projectCardImg]]</div>
                  </div>
             
           </div>

        the result are different "cards", which hold the teaser for a project. the div id’s are generated by modx dynamically based on the tv "Projektnummer".
        when an entry is clicked, i want to have the js-effect before changing page, so i have to call the new page via js, which is done like this:

                       $("#overview").find(".entry").click(function() {//add function on click for every div with class "entry"
        		        var clickedid=$(this);
        
        	                $("#overview").find(".entry").each(function(e){//fade all cards except the clicked one
        			       if($(this)!=clickedid){
        			            $(this).animate({opacity: "0"}, "slow");
        			            }			
        	                });//end each
        
        	                var entry_pos=$(this).offset();//get the position of the card
        	                createCookie("paletteX",entry_pos["left"]);//store position in cookie
                                createCookie("paletteY",entry_pos["top"]);
                                createCookie("bgimgstore",$("#bgimg").attr("src"));//store displayed background image in cookie
                                createCookie("currentId", clickedid);//store current project id in cookie (maybe useful later)
                               
                                var nexturlphp="index.php?id=14&P="+$(this).attr("id");//the project page has modx-id 14. concatenate with parameter p for project, which comes from the div id (from modx)
                                
                               
                                $($(this).children()).fadeOut("slow");fade //fade the content of the clicked div
                                setTimeout(location.href=nexturlphp,500);//after a short while (fading takes a little), redirect to the project page with parameter P, which is the projectnumber
        
        
                                });
          
        	        $("#page").find(".entry").each(function(e){//on dom ready, set all cards to visible again.
        	                $(this).css("opacity","1");
        	        });


        so i end up with the browser calling the page:http://fuchs.raumanstalt.ch/index.php?id=14&P=108

        the project page should now be able to take the value of P with the following snippet and store it in $project, then echo to my code:

        the snippet:
        <?php
        $project='';
        $project = $_GET['P'];
        echo $project;
        ?>



        NOW,

        i want to call getResources to fill in the content for the clicked Project. So i would have to look through all the project entries to see which one has the same TV "Projektnummer" as the $project variable.

        and then fill the found contents into the infoTpl chunk:

        <div class="projectnav_content">
                    <h2>[[+tv.projectName]]</h2>
                    <br />
                    <p>[[+tv.projectTxt]]</p>
        </div>


        as for now, the call looks like this:
        [[!getResources? &parents=`[[~2]] &processTVs=`1` &includeTVs=`1` &where=`{"tv.Projektnummer:LIKE":"[[getProjektnummer]]"}` &tpl=`infoTpl`]] 

        but i’m very sure, there’s something wrong with that

        hope i could explain a bit better..


          • 4172
          • 5,888 Posts
          ok, so your projects are resources?

          why not calling that resources directly instaed of calling them on page 14 with getresources?

          are they published?
          which resource-ids do they have?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 12990
            • 6 Posts
            yes they are resources..

            but if i wanted to call them directly, i would have to make the call from within javascript, right?
            seen from the opposite side, how could modx know which card the user clicks? the project id is not the same as the modx page id...
            the aim is to build a fully dynamic site with no hard coding whatsoever except the tv’s.
              • 4172
              • 5,888 Posts
              If you want to have the Projektnummer in your url instaed of the resourceid turn friendlyURLs on.
              Then put the Projektnummer into your alias and let modx generate your url.
              You call that generated url in your getResources-tpl with
              [[~[[+id]]]] 


              Then let the javascript read this url and load your page.

              If you still want to use getResources you can try:
              &tvFilters=`Projektnummer==[[!getProjektnummer]]`
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 12990
                • 6 Posts
                wow. seems fairly simple. and robust. i guess this is more how modx works?
                i’ll try this solution, it bugs me though that i can’t find the solution to the setup i made.. undecided

                thank you! if i stumble again, you’ll find my posts here..