Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-04-27 05:27:05

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

add id attribute to all article tags

Hi all,

if <txp:permlink /> tag has an id="XX" attribute that outputs the link to the specified article, couldn’t be useful to have it on other article tags like <txp:title />?

Very similar to what ied_doArticle does

I must admit I’m not totally sure about requesting this feature, because this could lead to some Frankestein-style blocks, or also, to performance issues, or breaking TxP semantics (although this will depends on the user not being clever at using this).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2008-04-27 17:56:32

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: add id attribute to all article tags

<txp:article_custom /> has an id attribute, so with a suitably crafted form you could do something like this: <txp:article_custom id="42" form="just-the-title" />. In the upcoming 4.0.7 release, we will add container capabilities to several tags, so this would be further simplified (?) to <txp:article_custom id="42"><txp:title /></txp:article_custom>.

Wouldn’t that suffice?

Offline

#3 2008-04-27 20:00:06

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: add id attribute to all article tags

Hi wet, thanks for your reply.

Yes, I know about the first possibility you mentioned (an article_custom tag and a form).
And about the second one, it’s good to know about it. (I’ve read about it before, when someone requested it, but can’t find the thread).

But back to the request, the reasoning behind it is: <txp:permlink id="123">Text</txp:permlink> works without all the article_custom hassle.
So, the request was more related to consistency between article tags.

Going back to the upcoming feature of article_custom as a container tag, what else will be able to do if an article ID isn’t specified?
Will it iterate over the contained HTML/Txp tags?

In that case, is it posible to add a wraptag attribute to the tag? So, for example, it will be possible to iterate thru a list of articles as <li> and output also the <ul> wrapping tag (only if the iteration outputs something, because if it returns empty, the ul shouldn’t be outputted?)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2008-04-27 20:13:01

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: add id attribute to all article tags

When using article_custom as a container tag, the contained tags will be parsed instead of a form.

Consistency between tags is nice, but you can push it too far and adding an id attribute to all article related tags just causes a lot of code duplication for something that isn’t really needed that often and can be done just as well with article_custom.

Offline

#5 2008-04-27 20:28:29

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: add id attribute to all article tags

ruud wrote:

When using article_custom as a container tag, the contained tags will be parsed instead of a form.

Cool. And will <txp:article /> also be a container tag? If yes, I think it will be very time saver to create article mark-up directly on page templates by just wrapping a bunch of article tags inside a pair of <txp:article></txp:article> tags…

Consistency between tags is nice, but you can push it too far and adding an id attribute to all article related tags just causes a lot of code duplication for something that isn’t really needed that often and can be done just as well with article_custom.

You are right. Maybe not to all articles, but then it will become more a matter of preferences to which tags could the id attr be extended. I found it very common to do something like this:
<li><txp:permlink id="123">Article Title</txp:permlink></li>
for some custom hand-made navigation menu.
So I was thinking of being able to do this:
<li><txp:permlink id="123"><txp:title id="123" /></txp:permlink></li>

So <txp:title /> would be a candidate for me, but then other will come and have their opinions on which tags should have this attribute.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2008-04-27 20:38:44

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: add id attribute to all article tags

In that specific example, it may be faster to use article_custom, because that would use 1 query instead of 2 ;)

article and article_custom are mostly handled by the same function internally, so yes, both would work as a container tag.

For <txp:article /> you’d have the following options after this is implemented:

<txp:article> tags for both individual and list context </txp:article>
<txp:article form="individual"> tags for use in list context </txp:article>
<txp:article listform="list"> tags for use in individual context </txp:article>
<txp:article form="both" />
<txp:article form="individual" listform="list" /> 
<txp:article listform="list" />
<txp:article />

Only the first three are new.

Offline

#7 2008-04-27 21:54:50

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: add id attribute to all article tags

Wow!
My brain exploded.

So, if I’m getting right #2 and #3, this one shouldn’t “work”, right?

<txp:article form="individual" listform="list">some tags</txp:article>

(with “shouldn’t work” i mean it should ignore the inside tags)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#8 2008-04-27 22:06:25

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: add id attribute to all article tags

Correct.

Offline

#9 2008-04-28 05:49:01

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: add id attribute to all article tags

ruud wrote:

<txp:article form="individual"> tags for use in list context </txp:article>

So, in this case, the tag will iterate (sorry if is not the correct programming word for this) over the fetched list of articles and render them using the contained tags.
I answer myself: yes, that’s the only way for this to work.

And what about the wraptag request for <txp:article />. Does it makes sense? I think it does.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2008-05-01 21:47:16

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: add id attribute to all article tags

r2869, could use some daring testers.

Offline

#11 2008-05-17 20:42:42

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: add id attribute to all article tags

Could <txp:article_custom /> support multiple values for id attribute?

Like this: <txp:article_custom id="3,15,28" />
That would iterate over the form (or the contained thing on upcoming container txp:article/txp:article_custom tags) and output articles with id 3, 15, 28.

Does it make sense?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#12 2008-05-17 21:23:03

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: add id attribute to all article tags

Would you mind testing…

In publish.php, in the doArticles function, replace:

$id        = (!$id)        ? '' : " and ID = '".intval($id)."'";

with:

$id        = (!$id)        ? '' : " and ID IN (".join(',', array_map('intval', do_list($id))).")";

Last edited by ruud (2008-05-18 08:27:27)

Offline

Board footer

Powered by FluxBB