We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26648
    • 5 Posts
    I have a TV that is called Country and it is a list of countries. I then have a country page that pulls in other resources with the TV Country that matches. I have that working using getPage. I want to conditionally show a button based on if there are any resources that match. So if there are no resources that matches the county, then the button will not show. Am I doing this in a snippet? Is there an example out there that someone could point me to?

    Thanks!
    Shawn
      • 4172
      • 5,888 Posts
      you could use the tplWrapper - property of getResources and put the button into the wrapper-tpl
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 26648
        • 5 Posts
        Thanks Bruno.

        Sorry again for the double-posting...

        So how does the conditional work? The button I want to show is not in the same area as the getResource call. But it is based on whether there are resources or not. From what I am understanding about the tplWrapper, it will wrap the resource with the code in the tpl. That would work for the entire section. Maybe I am not understanding it correctly.

        Still getting used to ModX...

        Thanks!

          • 26648
          • 5 Posts
          I am sure there is a more efficient way, but here is what I have done and it is working.

          [[!getPage:ifnotempty=`[[$partnersBtn]]`?
          				&elementClass=`modSnippet`
          				&element=`getResources`
          				&parents=`574`
          				&limit=`1`
          				&pageVarKey=`page`
          				&includeTVs=`1`
          				&includeContent=`1`
          				&showHidden=`1`
          				&sortby=`{"publishedon":"DESC"}`
          				&tpl=`mis_partner-grid-item-tpl`
          				&tvFilters=`country==[[*Country]]`
          			]]


          What this is doing is looking for resources in a TV category of Country (Mexico, Guatemala, etc.) If there are no resources, it will show my partnersBtn snippet.

          I have 2 buttons and 2 headings that need to do this. Is this going to slow my page down with the getResources call?

          I am open to suggestions.

          Thanks!
            • 4172
            • 5,888 Posts
            you could do it also this way, setting the result of getPage into a placeholder:

            [[!getPage?
                            &elementClass=`modSnippet`
                            &element=`getResources`
                            &parents=`574`
                            &limit=`1`
                            &pageVarKey=`page`
                            &includeTVs=`1`
                            &includeContent=`1`
                            &showHidden=`1`
                            &sortby=`{"publishedon":"DESC"}`
                            &tpl=`mis_partner-grid-item-tpl`
                            &tvFilters=`country==[[*Country]]`
                            &toPlaceholder=`mis_partner-grid`
                        ]]
            
            [[!+mis_partner-grid:ifnotempty=`[[$partnersBtn]]`]]
            
            [[!+mis_partner-grid]]
            
            [[!+mis_partner-grid:ifnotempty=`[[$partnersBtn]]`]]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!