We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18463
    • 121 Posts
    Martijn van Turnhout Reply #1, 13 years, 1 month ago
    Hi all,

    I’m having a lot of trouble with getResources. Especially with the tvFilters-parameter.

    I’ve created a folder ("Kantoren") which contains the following code:

    <div id="wrapper_cabins">
      <ul id="overview_cabins">
        [[getResources? &parents=`2` &tpl=`cabin_overview` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &hideContainers=`1` &showHidden=`1` &tvFilters=`cabin_category==1`]]
      </ul>			
    </div>
    


    The "cabin_overview" chunk contains the following code, which works flawlessly

    <li><a href="[[~[[+id]]]]"><img src="[[+cabin_image:phpthumbof=`w=160&h=98&zc=1`]]" width="160" height="98"><br> [[+pagetitle]]</a></li>
    


    I’ve attached the following Template Variable to the page which I’ve put inside parent ’2’: a Check Box named "cabin_category" with the following Input Option Values.

    Kantoren==1||Industrie==2||Bouw==3||Scholen==4
    


    The tree is setup like this:

    Cabintypes (folder)
      - Kantoren (folder, which contains the 1st code)
      - Industrie (folder)
      - Bouw (folder)
      - Scholen (folder)
      - Type A (page which contains the check box variable)
    


    Now, I’d like to filter the results per folder. A template which has the option "Kantoren" checked, should be displayed with the very first code above right? And yet, it doesn’t work. I’ve left out the tvFilters parameters and it works like a charm then, but that’s not what I’m looking for. I want to filter the results, based on what is and isn’t checked with "cabin_category".

    So what am I doing wrong? I’m using Revo 2.1 RC by the way.
      • 25483
      • 741 Posts
      Why do you want to use the TV’s while you use a folder structure already? Looks like a double functionality to me.
        with regards,

        Ronald Lokers
        'Front-end developer' @ h2o Media

        • 18463
        • 121 Posts
        Martijn van Turnhout Reply #3, 13 years, 1 month ago
        Not if you want to make sure 1 page can be viewed in multiple folders. That’s what I’m looking for.
          • 18463
          • 121 Posts
          Martijn van Turnhout Reply #4, 13 years, 1 month ago
          The great b03tz helped me out! My problem was using multiple checkboxes for 1 page. Let’s say I want to put the page in categories 1 and 2. The result of [[*cabin_category]] would be "12" in that case. However, that option is not available. The check box options aren’t automatically separated, which I thought would be the case.

          The solution is simple: use a wildcard. This way, getResources can still find "2" inside "12". Like below.

          <div id="wrapper_cabins">
            <ul id="overview_cabins">
              [[getResources? &parents=`2` &tpl=`cabin_overview` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &hideContainers=`1` &showHidden=`1` &tvFilters=`cabin_category==%2%`]]
            </ul>			
          </div>
          


          Patrick, many thanks again!

          On a sidenote: this should be made clearer in documentation.
            • 25483
            • 741 Posts
            You have to set the output of the TV to "delimeter", this way you can add a separator between items. But you still need to use the % wildcards to make it work! Also use a name within your variables, because else you will get problems if you will have 10+ categories (because 1 is in 1 and in 10).

            So it’s better to use type1, type2, type3, etc as values.
              with regards,

              Ronald Lokers
              'Front-end developer' @ h2o Media

              • 18463
              • 121 Posts
              Martijn van Turnhout Reply #6, 13 years, 1 month ago
              Excellent tips, thanks!
                • 20912
                • 21 Posts
                Quote from: Ronald at Mar 30, 2011, 06:18 PM

                You have to set the output of the TV to "delimeter", this way you can add a separator between items. But you still need to use the % wildcards to make it work! Also use a name within your variables, because else you will get problems if you will have 10+ categories (because 1 is in 1 and in 10).

                So it’s better to use type1, type2, type3, etc as values.
                Can u help me with my problem? Details you can find at http://modxcms.com/forums/index.php/topic,63782.0.html
                • Quote from: ronaldlokers at Mar 30, 2011, 06:18 PM
                  You have to set the output of the TV to "delimeter", this way you can add a separator between items. But you still need to use the % wildcards to make it work! Also use a name within your variables, because else you will get problems if you will have 10+ categories (because 1 is in 1 and in 10).

                  So it's better to use type1, type2, type3, etc as values.

                  I've just been working on this problem, and found the following to be the most reliable, as even in a string value you could get this problem, as using the pagetitle causes problems when someone changes the value of pagetitle.

                  My Input Option Values are as follows:

                  @SELECT CONCAT(pagetitle,' (',id,')') AS `name`, CONCAT('*',id,'*') as `id` FROM `modx_site_content` WHERE `deleted` = 0 AND `template` = 11


                  This ensures that the value of each selected resource is "more unique" than the uniqueness of the ID alone, because Modx will never naturally assign an ID with an '*' in it. Each resource has an ID of '*id*'.

                  Then, when declaring getResources, my filter is:

                  &tvFilters=`list.top10.categories==%*[[*id]]*%`


                  This means I won't run into problems where "11,12=%1%" is true. Instead we get "*11*,*12*=%*1*%" which is false, and ultimately what we're trying to achieve.

                  Is this too hacky? I works, but it's not exactly elegant.
                    • 4172
                    • 5,888 Posts
                    you could also make sure to have '||' at front and at end of the list in your TV

                    ||25||26||30||40||

                    then you could use
                    &tvFilters=`list.top10.categories==%||[[*id]]||%`
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                    • How would you do that though, ensuring "||" appears at the start and end of the list? The TV only prints out as 25||26||27, so ||25|| would never match.

                      It's all a bit of a horrible hack at the end of the day, resolved with some kind of :contains filter (for lists, not substring).

                      I'm guessing this doesn't work (don't have modx in front of me to check):

                      &tvFilters=`||list.top10.categories||==%||[[*id]]||%`