SID-02261: Using Table within Search
| Status: |
Answered |
TWiki version: |
6.0.1 |
Perl version: |
|
| Category: |
TablePlugin |
Server OS: |
|
Last update: |
9 years ago |
I'm struggling with understanding what I am doing wrong trying to use
TABLE within a
SEARCH.
I would like to create a "new" table when a certain condition is met. This appears to work successfully however I'm unable to figure out how to format each table. Hopefully this is demonstrated in the example below:
%SEARCH{"META:FORM.*[U]serForm;META:FIELD.*[F]irstName.*value=\"BobB.*" web="%USERSWEB%" type="regex" nonoise="on"
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | *Name* | $n | $topic |, | $topic | )}$percnt"
excludetopic="TWiki*"}%
The results from the search above are shown below:
$percntTABLE{columnwidths="300px"}$percnt
$percntTABLE{columnwidths="300px"}$percnt
$percntTABLE{columnwidths="300px"}$percnt
$percntTABLE{columnwidths="300px"}$percnt
$percntTABLE{columnwidths="300px"}$percnt
--
Jani Hamalainen - 2016-10-12
Discussion and Answer
Not sure what your objective is with this search, but it looks like you run into escape hell with:
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | Name | $n | $topic |, | $topic | )}$percnt"
With your format,
$percntCALCULATE{}$percent is delayed until after the SEARCH, as you intended. However,
$dollarpercntTABLE{}$dollarpercnt resolves to
$percntTABLE{}$percnt after SEARCH. The CALCULATE does not resolve the $percnt. If you want to delay that and resolve by CALCULATE you can escape it CALCULATE specific:
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $NOP(%)TABLE{columnwidths=\"300px\"}$NOP(%) $n | Name | $n | $topic |, | $topic | )}$percnt"
The
$NOP(%)TABLE{columnwidths=\"300px\"}$NOP(%) resolves to
$NOP(%)TABLE{columnwidths="300px"}$NOP(%) after SEARCH, and to
%TABLE{columnwidths="300px"}% after CALCULATE.
--
Peter Thoeny - 2016-10-13
Thanks for the explanation Peter. I did intentionally include the extra $dollar surrounding the TABLE because I was trying to demonstrate that I would like the
TABLE to be added whenever the $IF statement was true. Sorry that I forgot to mention it thought but I felt removing the $dollar made the output a lot more confusing (and less clear what I was trying to do).
I did try what you had suggested though and followed through your explanation. It didn't occur to me before that
SEARCH finished prior to
CALCULATE when using
$percnt. The results are still not exactly what I was looking for but maybe I can figure it out from here. My goal is to visible see a new table (and allow formatting) when the
$IF condition is met.
| Name |
| Name |
| Name |
| Name |
| Name |
--
Jani Hamalainen - 2016-10-13
I couldn't figure out how to integrate the TABLE function into the SEARCH (as shown above) so I took the approach of changing the CSS to display the table like I desired.
A brief summary for anyone else with a similar desire:
- Add the CSS to your topic:
<style>
.MyTable .twikiTable {
width: 100%;
vertical-align: middle;
text-align: center;
}
.MyTable .twikiTable tr {
vertical-align: middle;
text-align: center;
}
.MyTable .twikiTable td {
vertical-align: middle;
text-align: center;
}
</style>
- Enclose your search results within a div class = MyTable (or whatever you name the class in the CSS).
<div class="MyTable">
%SEARCH{"META:FORM.*[U]serForm;META:FIELD.*[F]irstName.*value=\"BobB.*" web="%USERSWEB%" type="regex" nonoise="on"
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | *Name* | $n | $topic |, | $topic | )}$percnt"
excludetopic="TWiki*"}%
</div>
--
Jani Hamalainen - 2016-10-25
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.