Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-06-15 07:17:53

FireFusion
Member
Registered: 2005-05-10
Posts: 698

if_article_keyword

I’ve just come across of some situations where tag would be really helpful.

<txp:if_article_keywords> would be a conditional based on the keywords entered for that article.

Last edited by FireFusion (2007-06-15 07:19:08)

Offline

#2 2007-06-16 01:44:56

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

 function if_article_keywords($atts, $thing)
	{
		global $thisarticle;
		assert_article();
		extract(lAtts(array(
			'keyword' => '',
		),$atts));
	return parse(EvalElse($thing, do_list($thisarticle['keywords'] , $keyword)));
	}


Something like this would work for some situations (though this exact code appears to be very 
friendly as yet and is evaluating everything as true for some reason ?). my question would be - 
Are you needing to match a single keyword to a list : all keywords in a list : any to any ? all to all ?. 
think most situations could be done fairly easily, if it hasn't already been done, given perhaps 
tags for specific circumstances.

Last edited by rsilletti (2007-06-16 01:46:32)

Offline

#3 2007-06-16 02:06:18

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: if_article_keyword

You’re sure you’re not looking for the keywords= attribute of the txp:article tag?

Offline

#4 2007-06-16 06:39:47

FireFusion
Member
Registered: 2005-05-10
Posts: 698

Re: if_article_keyword

No i’m thinking of something like the if_custom_field tag but for keywords.

Offline

#5 2007-06-16 17:03:50

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

Given that the keywords field doesn’t require a name attribute to find it on an article by article basis, that would leave you with the val attribute usage. Keywords are used in a comma delimited list, this leaves you with the choice of matching one memeber of the list with a value that you pass it, or matching any member of an attribute list passed in with any member of the keyword list (ala if_article_category), or matching all members of the attribute list with all members of the keyword list (I haven’t tried this but I’m sure it can be done). Which of these options would best fit your need?

Offline

#6 2007-06-23 19:36:33

anoke
Archived Plugin Author
Registered: 2006-04-15
Posts: 152

Re: if_article_keyword

do_list()? O.o

BTW, Shouldn’t all keywords be matched for the comparision to return true? One can always nest comparisons to get the keywords more narrowly matched. Or something.


- When chickens are cold, they roost in trees; when ducks are cold, they plunge into water -

Offline

#7 2007-06-23 20:38:08

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

The intent of the code example above was to check for a match of 1 keyword as an attribute against that keyword’s presence in the keyword list (hence do_list() ), it is one thing that some may want, matching all against all to return true may also be desired. Whether to write a one size fits all tag or seperate tags for different needs would be a matter of how complicated you want to make tag usage for the user.

Last edited by rsilletti (2007-06-23 20:40:28)

Offline

#8 2007-06-23 22:27:52

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

	function if_article_keyword($atts, $thing)
	{
		global $thisarticle;
		assert_article();
		extract(lAtts(array(
			'keyword' => '',
		),$atts));
	return parse(EvalElse($thing, in_list($keyword, $thisarticle['keywords'])));
	}


Yup - do_list was the wrong function, this works
to match a single keyword against an article keyword
list on an article by article basis.

Would a second tag be a good idea to compare two lists,
Or would it be better to incorporate it in this function?

Last edited by rsilletti (2007-06-23 22:29:57)

Offline

#9 2007-06-24 01:38:36

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

This plugin will do most anything for a conditional tag that you could use, I think, it could use some testing but I haven’t been able to break it yet.

ras_if_article_keywords the Swiss Army Knife model.

Last edited by rsilletti (2007-06-26 00:32:55)

Offline

#10 2007-06-24 06:30:44

anoke
Archived Plugin Author
Registered: 2006-04-15
Posts: 152

Re: if_article_keyword

One plugin to find them.

How about a negation mode too? And could the parameters be just “list” as the “keyword” is already mentioned – the purpose of list is quite clear due the context imho. (I’m a lazy typist when it comes to repeating words words..)

Or just to make things a bit absurd could they be combined if_keywords yes="foo, bar" no="bazzy" :D

edit:
(just spent an hour figuring this plugin out). Do emphasise “all” and “all” in plugin’s documentation?-)

edit-two:
Now to think of it again – maybe two plugins are better? One to catch if keywords are set and another to do comparison. That way nested if tags won’t come a problem so soon. <if_has_keywords><if_keyword list="blah blah"></if_keyword><else/></if_has_keywords> or something.

Last edited by anoke (2007-06-24 20:30:30)


- When chickens are cold, they roost in trees; when ducks are cold, they plunge into water -

Offline

#11 2007-06-24 17:24:38

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

Negation can be accomplished with the else clause, which is a choice available, and – yes, “list” occured to me but it didn’t seem descriptive enough.

Offline

#12 2007-06-24 19:09:54

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: if_article_keyword

<txp:ras_if_article_keywords keyword_list=“foo” mode=“4”>
<txp:ras_if_article_keywords2 keyword_list=“bar” mode=“4”>
<txp:else />
<p>bar</p>
</txp:ras_if_article_keywords2>
</txp:ras_if_article_keywords>

I’ve made arrangements like this work by duplicating the function and changing
the name so I can nest them. I’m not entirely clear on all the ins and outs with
Evalelse so I wouldn’t recommend trying this at home, so to speak.

The idea of combining both negation and affirmation in the same function may
be doable, its software after all, but maybe more confusing than it would be worth.

And yes, I’ll try to make the help file more clear, it can take a bit to figure out
what this is actually doing; its why I was considering two or three seperate tags.

Offline

Board footer

Powered by FluxBB