Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2004-09-17 12:21:06
- Kibitzer
- Member
- From: Melbourne, Australia
- Registered: 2004-05-24
- Posts: 44
plugin tags inside article body
Hi all. Some advice on plugin design needed.
When my reviews site was under MT(Movable Type) I used to head each article with HTML for the star ratings and category images. So if I rated a movie as three stars I’d enter:
<img src="images/3_stars.gif" />
<img src="images/icon-movie.gif" align="right"/>
When I converted to TXP I thought I’d dust off my (rusty) PHP and convert this into a tag I could stick in the article body like this:
<txp:abc_ratings rating="3" category="movie" />
So, cool, no worries: easy. Then I thought how dumb it was to include a category attribute when the article itself is already categorised so I figured I’d interrogate the article in my code, extract the category and stick it in the tag’s output as part of the second image name. I’ve tried a lot of stuff, checked Dean’s code, checked other plugins but I just can’t do it.
Now, the thing about TXP plugins I’ve seen — and the built-in tags for that matter — is that they’re designed for forms, pages, etc, not article bodies. True? And I think this is why I can’t get the article’s category within my code. I installed a plugin which outputs a “posted under cat1|cat2” type thing and tried it within an article body — doesn’t work.
So…
Can I write a plugin to do what I want? Or are plugins just not designed for use within article bodies?
(BTW I’ve thought of ways around this like having two plugins: one for the form and one for the article; or using the “closet, cupboard” fields to store the rating — but I’d still like to know whether what I’ve said above is possible.)
Last edited by Kibitzer (2004-09-19 02:18:31)
VC200 Member #69 — VCTWO Member — Mixed Gorilla
“YES!” “That would be an ecumenical matter!”
Offline
#2 2004-09-19 02:17:58
- Kibitzer
- Member
- From: Melbourne, Australia
- Registered: 2004-05-24
- Posts: 44
Re: plugin tags inside article body
Hi again. I don’t mind that there’s no replies but i am curious — is the question I asked above too stupid because the answer’s so obvious, or is it too long, or does no-one know? I’m just looking for a pointer, is all.
Let me re-state is more simply: I expected that if a <txp:category1 />
tag is in an article body (not a page or form template), the category would be displayed in the output. It’s not; how can I do this coding my own tag?
VC200 Member #69 — VCTWO Member — Mixed Gorilla
“YES!” “That would be an ecumenical matter!”
Offline
#3 2004-09-19 02:37:07
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: plugin tags inside article body
Maybe not for article bodies (if you mean within your article’s main text), but that doesn’t mean it couldn’t look like it was part of the article.
i.e: plugins are often tags, tags are what display the article’s body, categories, etc.
You could make use of custom fields and this plugin:
rei_show_custom
Offline
#4 2004-09-19 05:51:03
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: plugin tags inside article body
You don’t need to put tags in articles to do what you want. Write a plugin that displays images (icons and stars) based on the content of the article (category, cupboard, whatever). Put the plugin tag in your article form.
Writing a plugin is easy enough if you’re competent with PHP. There are some pointers in this thread. If that’s not enough to get you started, you probably need to learn more about PHP first.
Alex
Offline
#5 2004-09-19 06:59:17
- Kibitzer
- Member
- From: Melbourne, Australia
- Registered: 2004-05-24
- Posts: 44
Re: plugin tags inside article body
Thanks for the replies, I appreciate it.
My PHP, though rusty, is adequate. I already wrote one plugin — check the Central Plugin List — it’s just not very useful.
Zem, certainly for the category image I can write a plugin and I may do so. And I know I can use the extra article fields, too.
What I don’t get is why plugin code can’t see article attributes when inserted in the article body (ie, in the article’s main text — thanks mary for making that clearer, I should have said that first up). As mentioned above, I’ve written a plugin/custom tag which works when inserted like so: <txp:abc_ratings rating="3" category="movie" />
. This works just fine because the code relies only on the tag attributes, not the article. It also means TXP does process tags within articles but apparently not in the same way as it processes them in forms, etc.
Anyways, thanks all. I probably should just dive into the TXP code and see for myself.
VC200 Member #69 — VCTWO Member — Mixed Gorilla
“YES!” “That would be an ecumenical matter!”
Offline
#6 2004-09-19 07:24:29
- Kibitzer
- Member
- From: Melbourne, Australia
- Registered: 2004-05-24
- Posts: 44
Re: plugin tags inside article body
Ah. In this thread I noticed a statement:
> zem wrote:
> $thisarticle is only available within an article form.
That tells me why I can’t get the category inside an article body ‘cause $thisarticle is what I was using to get it — now it’s clear. Hmmmm. Just seems it should be available…
VC200 Member #69 — VCTWO Member — Mixed Gorilla
“YES!” “That would be an ecumenical matter!”
Offline
#7 2004-09-19 13:09:00
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: plugin tags inside article body
> > $thisarticle is only available within an article form.
> That tells me why I can’t get the category inside an article body ‘cause $thisarticle is what I was using to get it — now it’s clear. Hmmmm. Just seems it should be available…
It is.
When I said “only available within”, I meant “not available outside an article form” (i.e. not in a page context. Technically, an article is within an article form.)
I’ve found one bug with Textpattern tag handling inside article bodies. There might be others. No point battling that just now, with a new release due soon.
That’s mostly moot anyway. Store your rating in one of the custom fields as an integer. Write a plugin that displays the appropriate image based on the content of that field. Put your plugin tag in your article form.
Alternatively, if you’re going to the trouble of writing <txp:abc_ratings rating="3" />
, you could use !/images/3.gif!
instead. Shorter, with no plugin required.
Alex
Offline
#8 2004-09-19 22:54:31
- Kibitzer
- Member
- From: Melbourne, Australia
- Registered: 2004-05-24
- Posts: 44
Re: plugin tags inside article body
I want a plugin because it separates form from content. If I want to restyle my site to use… I dunno… dancing monkeys rather than stars and also drop-cap the first letter, I can just update the plugin rather than re-tool each article.
I’m not convinced that using a custom field is the best way to go but I am thinking about it.
Thanks again for the feedback.
VC200 Member #69 — VCTWO Member — Mixed Gorilla
“YES!” “That would be an ecumenical matter!”
Offline
Pages: 1