We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23372
    • 7 Posts
    Hello newbee over here...

    I have a table with some tv. These tv are in seperate rows/ columns
    But not every page need those tv.

    Is it possible to delete the row if the row is empty (no tv in it)?

    example:
    <table border="0" id="testtable" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="4"><h1>[*longtitle*]</h1></td>
    </tr>
    <tr>
    <td id="test1">[*test1*]</td>
    <td id="test2">[*test2*]</td>
    <td id="test3">[*test3*]</td>
    <td id="test4">[*test4*]</td>
    </tr>
    <tr>
    <td id="test5">[*test5*]</td>
    <td id="test6">[*test6*]</td>
    <td id="test7">[*test7*]</td>
    <td id="test8">[*test8*]</td>
    </tr>
    </table>

    So when the row with test5 to 8 is empty....I dont want to show this row

    And YES i know DIV’s are better....but in this case it isn’t for me
      • 25663 MODX Staff
      • 12,272 Posts
      Write a custom snippet or use PHx along the lines of [+phx:if=`[*test5*]`... and wrap it around each TR (or make the TRs as chunks to make it even easier. Not sure how to determine if the TV is blank or not as it might require a custom modifier.

      http://wiki.modxcms.com/index.php/PHx
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 23372
        • 7 Posts
        thank you for your fast reply....

        I was looking at the wiki, but it isn’t very simple to read.

        First of all I have to make a snippet ---> call it "delete_row"

        [+phx:if=`[*test5*]``[*test6*]``[*test7*]``[*test8*]`

        + something with empty huh

        And after that...go to the template and add the snippet around the <tr></tr>
        {{delete_row}} 
           <tr>
              <td id="test5">[*test5*]</td>
              <td id="test6">[*test6*]</td>
              <td id="test7">[*test7*]</td>
              <td id="test8">[*test8*]</td>
           </tr>
        


        Am I in the right direction?
          • 25663 MODX Staff
          • 12,272 Posts
          Not at all really. You should look at the MODx basics in the documentation section to get a better understanding of the difference between snippets, chunks and placeholders first. I don’t have a ton of time to dig into this further right now but I’m sure someone will chime in soon.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 7231
            • 4,205 Posts
            A snippet is built with PHP code. You can set variables to be used in the snippet by by including parameters to the snippet call. A snippet call consists of the snippet name followed by the parameters (each parameter enclosed in back ticks). An example of a snippet call is:

            [!SnippetName? &param1=`value1` &param2=`value2`!]

            You can use TVs as parameters in the snippet call like this:

            [!SnippetName? &param1=`[*tvValue1*]` &param2=`[*tvValue2*]`!]

            You were trying to use PHx which allows some logic to otherwise static placeholders. I haven’t gotten into PHx so I can’t help fix the syntax. However as with everything in MODx there is more than one way to get things done. I would use a snippet with conditional logic to determine if a TV has a value and then return the row or not. An existing snippet that can be used for this is the tvConditional snippet that returns a chunk according to the result of the TV condition. It is a very simple snippet and gives you a good look at how to access TV values and return a chunk.

            In case you don’t already know, a chunk is a bit of xHTML code that can be placed within your template. Chunks are identified by brackets {{chunkName}}, TVs and document variables use the [*varName*] syntax and snippets use [!snippetName!] for un-cached or [[snippetName]] when cached.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]