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
-
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
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? ¶m1=`value1` ¶m2=`value2`!]
You can use TVs as parameters in the snippet call like this:
[!SnippetName? ¶m1=`[*tvValue1*]` ¶m2=`[*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.