Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-10-13 03:32:38
- wolfcry911
- Member
- From: MA, USA
- Registered: 2006-06-30
- Posts: 51
Looking for ideas on table maintenance
I’m developing a site that contains a section with monthly news summaries. Along with the narrative are two simple tables (2 col. x 16 rows) where the second column’s numbers change every month.
I’m looking for the best way to implement this so that the (technically challenged) end-users can easily enter the narrative and table data. I’ve toyed with idea of using aks_table plugin and putting the tables into the excerpt, but I can’t guarantee the end-user will know how to implement that (as easy as it is). I’m wondering if I should separate the narrative from the table data, or use custom fields (doesn’t seem appropriate here), or some other solution.
Any help is appreciated.
Offline
Re: Looking for ideas on table maintenance
Your excerpt idea sounds most manageable with you controlling the txp:aks_table
command and the excerpt content serving as the filling (you’ll just need to strip off the p tags or make the excerpt non-textiled), e.g.
<txp:aks_table h="1" id="monthly_results">
Column heading 1 Column heading 2
<txp:rah_replace from="<p>,</p>" to=""><txp:excerpt /></txp:rah_replace>
</txp:aks_table>
Alternatively if you want to use your own notation, e.g. heading:value
you could write your own using the same principle but with rah_replace or pax_grep for more complex search and replace combinations, e.g.:
<table id="monthly_results">
<thead>
<tr>
<th>Column heading 1</th>
<th>Column heading 2</th>
</tr>
</thead>
<tbody>
<txp:rah_replace from="<p>,</p>,:,
" to="<tr><td>,</td></tr>,</td><td>,</td></tr><tr><td>"><txp:excerpt /></txp:rah_replace>
</tbody>
</table>
Both untested, but you get the principle. The new line in the “from” attribute is intentional (see this comment in the rah_replace thread).
If rah_replace complains about the new line, you could try pax_grep in combination with the regex codes for new line and “:”.
Last edited by jakob (2011-10-13 07:42:39)
TXP Builders – finely-crafted code, design and txp
Offline
#3 2011-10-14 12:25:57
- wolfcry911
- Member
- From: MA, USA
- Registered: 2006-06-30
- Posts: 51
Re: Looking for ideas on table maintenance
Thanks jakob. I like the idea of using our own notation…
Offline
#4 2011-10-17 02:14:19
- wolfcry911
- Member
- From: MA, USA
- Registered: 2006-06-30
- Posts: 51
Re: Looking for ideas on table maintenance
Well, I’ve played around with these options a bit and I’m not satisfied.
After some thought, I was going to use your first suggestion jakob, but in conjuction with glz_custom_fields and two extra text area fields (instead of excerpt). Well, I tested fairly thoroughly with just the excerpt and never got it to work. I believe now that the aks_table needs to be in the write window when saved in order to process. In other words, I don’t believe I can use the aks_table plugin outside of the textile context.
Then I moved on to your next suggestion, and although I have it working, it seems a bit clunky. I (or the end-user) needs to eliminate tabs and replace with a colon and also make sure to keep an extra carriage return between entries – otherwise you get a br instead of a p.
Ultimately, I’d love what this person asked for here
Don’t know if it’s possible, but I’d be willing to pay for something like this.
Offline
Re: Looking for ideas on table maintenance
I had a closer look at the code in txp:aks_table and it is definitely built to be used with the body and excerpt fields as it includes a special routine that hooks into the publish/save event and adds a space in front of the txp:aks_table tag in case one forgets. In the example I showed it matches the heading line without any problems but then fails on the excerpt. I tried farming the rah_replaced excerpt into a variable and then including only that but without success. My guess is that aks_table doesn’t like txp tags in tags so you will need to include the aks_table tag within the excerpt after all (which was what you were trying to avoid).
Going back to the second approach, if you want tabs instead of a colon and no brs, try this:
<table id="monthly_results">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<txp:rah_replace from="<br />, <p>,</p>, ,
" to=",<tr><td>,</td></tr>,</td><td>,</td></tr><tr><td>"><txp:excerpt /></txp:rah_replace>
</tbody>
</table>
Note copy carefully as what look like blank spaces above are tab characters. The tab character in front of the first p is also intentional as that’s added to the excerpt on saving an article and results in a stray table cell if you don’t include it in the search and replace.
This is what I have in my excerpt (copied directly from the cells of an excel table):
square circle triangle pentagon
123 456 789 10
apples oranges pears cherries
and this is the output it produces:
<table id="monthly_results">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<tr><td>square</td><td>circle</td><td>triangle</td><td>pentagon</td></tr><tr><td>123</td><td>456</td><td>789</td><td>10</td></tr><tr><td>apples</td><td>oranges</td><td>pears</td><td>cherries</td></tr>
</tbody>
</table>
If you want cleaner html output change the rah_replace line as follows:
<txp:rah_replace from="<br />,
, <p>, ,</p>" to=",</td>
</tr>
<tr>
<td>, <tr>
<td>,</td>
<td>,</td>
</tr>"><txp:excerpt /></txp:rah_replace>
(look horrible but produces clean output – decide what you prefer to be more readable: the html output or your txp:code. Either way it makes no difference to the end user or visitor)
TXP Builders – finely-crafted code, design and txp
Offline
Re: Looking for ideas on table maintenance
jakob wrote:
My guess is that aks_table doesn’t like txp tags in tags
It’s not parsing the content. Try altering line 20 of aks_table to:
$lines=explode("\n", parse($thing));
and you should be good to go.
One thing though: in your first example, rah_replace doesn’t deal with the removal of the leading newline so the first cell is blank in your square/circle example text. You got round that in your second version.
A better approach than rah_replace might be etz_striptags here. Or, if you prefer a swiss army knife approach, I have a plugin that I’m just about to release which can strip tags as part of its other duties.
Hope that helps.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Looking for ideas on table maintenance
Try altering line 20 of aks_table
Ah, that’s good to know. Also means my initial approach wasn’t quite as bungled then after all.
One thing though: in your first example, rah_replace doesn’t deal with the removal of the leading newline
You mean the aks_table example and the leading tab (I think)…
A better approach than rah_replace might be etz_striptags here. Or, if you prefer a swiss army knife approach, I have a plugin that I’m just about to release which can strip tags as part of its other duties.
Yes, although you still need rah_replace or similar for the tabs. The swiss army knife is a godsend :-)
TXP Builders – finely-crafted code, design and txp
Offline
#8 2011-10-17 12:03:24
- wolfcry911
- Member
- From: MA, USA
- Registered: 2006-06-30
- Posts: 51
Re: Looking for ideas on table maintenance
wow, thank you both!
bloke, look forward to seeing your new plugin.
jakob, thanks for all that work – I had tried an example replacing the colon with a tab and using the break, but I made the mistake of simply replacing the closing p with the br and therefor had no opening table row or data (I didn’t account for the missing opening p). Your updated second approach will work perfectly for me – I was hoping the end-user could just copy paste the table they have into a field and be done with it.
Oh, incidentally, I’ll opt for clean html output over clean txp:code any day ;) – not sure why other than I like a clean finished product.
Offline
Re: Looking for ideas on table maintenance
jakob wrote:
You mean the aks_table example and the leading tab (I think)…
Uhh, yeah sorry. I didn’t check if it was a tab or a newline which was lame of me, but the result was the same: a bogus tab at the start of the list which threw everything off by one cell.
Yes, although you still need rah_replace or similar for the tabs.
You’re right. etz_striptags doesn’t trim()
. Again, sorry for the bogus info.
The swiss army knife is a godsend :-)
Yeah, I can’t get enough of it at the moment. In this case it trims by default and you can apply the strip_tags
format so it does the job of both plugins, woot!
In the end I got it to work by pasting this into my excerpt:
square circle triangle pentagon
123 456 789 10
apples oranges pears cherries
and then using the following in my default Form:
<txp:aks_table h="1" id="monthly_results">
Column 1 Column 2 Column 3 Column 4
<txp:smd_wrap format="strip_tags"><txp:excerpt /></txp:smd_wrap>
</txp:aks_table>
Of course, that is a simplistic case if you know there are always going to be 4 columns of data. To cope with variable headers would require more brainpower than I have available on a Monday.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online