Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » [archived] ptv_if

#1 2005-03-21 22:22:23

Borisch
Archived Plugin Author
From: Sweden
Registered: 2004-05-30
Posts: 15
Website

[archived] ptv_if

Notice: This thread is archived, this plugin is no longer available.

**********************************************************

Had the need for a proper conditional statement the other day; the “else” part of it to be specific. As I didn’t feel that creating a plugin checking for a negating condition, I instead wrote a quick conditional construct.

So…basically this is an if / else if / else tag that can be applied on already existing plugins and functions. It is made up of one “parent” tag inside which the conditions are written.

Example:
<pre><code>&lt;txp:ptv_condition&gt; &lt;txp:ptv_if plugin=“mdm_if_category” category=“Alpha”&gt; Content specific to Alpha category &lt;/txp:ptv_if&gt;

&lt;txp:ptv_else&gt; Content for everything else &lt;/txp:ptv_if&gt; &lt;/txp:ptv_condition&gt;</code></pre> (Yes…I am aware that the mdm_if_category has a negate function already =)

It also has support for 2 part comparisons of accessible variables, functions or absolute values, although I havent tested that part thoroughly and it currently uses eval() which is a potential security hazard when combined with user input.

If I recieve any response or reqests, I’ll probably be improving on it, if not…it will get archived away and improved upon when I need it to do something more =)

The else_if part is purely decorative as if can be used in its place just as well.

My todolist is:
Nested statements.
Singular boolean tests.
Proper comparisons with and, or, xor, groupings.
A way to use the plugins in a bit more elegant way.

<a href=“http://www.bobified.com/code/txp/ptv_if_0.3b.txt”>Download file</a>
<a href=“http://www.bobified.com/code/txp/ptv_if_0.3b.html”>Documentation URL</a>

Best regards
Borisch a.k.a. Petur

Last edited by Borisch (2005-03-21 22:24:00)


Instead of conquering the world, I’m collecting it in my attic.

Offline

#2 2005-03-21 23:03:25

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: [archived] ptv_if

a true conditional plugin. i would never have thought… :)
i remember months ago when Remillard was explaining to me the sense in having an ‘elseif’ available if you’re going to have an ‘if’.. so kudos!

what version of textpattern is this for, btw?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#3 2005-03-21 23:39:43

Borisch
Archived Plugin Author
From: Sweden
Registered: 2004-05-30
Posts: 15
Website

Re: [archived] ptv_if

Well…so far its an “imitation” of a conditional. I’m hoping to amend that in time.

As far as version, I’m guessing the latest =) ( 1.0rc1)
Although the only textpattern functions beeing used are parse and splat so it should be somewhat compatible. (At least while the pluginapi remains the same).


Instead of conquering the world, I’m collecting it in my attic.

Offline

#4 2005-07-06 05:41:58

asarbogast
Member
From: Arcata, CA
Registered: 2004-05-21
Posts: 33
Website

Re: [archived] ptv_if

Could I use this plugin to determine if a particular article is the most recent article?

On my front page I list the latest article in each of 3 sections using article_custom. I’d like to be able to distinguish which of these 3 articles is the most recent, so I can add a class and style it differently. It seems like I should be able to determine which article has the highest ID, but I’m not exactly sure how to do it.

Any pointers would be greatly appreciated!

Thanks,

Andrea

Offline

#5 2005-10-14 17:02:25

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: [archived] ptv_if

Hi,

I have a section named Shows displayed on my front page. I want to display the 3 most recent posts and then have a “More Shows….” link to the rest of the posts on the Shows page. My problem is… if there are a total of 3 or less posts for this section, I do not want the “More Shows…” link to appear… I’d like it to be omitted — or, if there are no current posts for this section, I’d like for it to say something like… “No shows at this time”

I found ptv_if and am wondering how I might use it to acheive this. Any suggestions?

thx,
Stacey

Offline

#6 2005-11-22 01:21:26

gb
New Member
From: Buenos Aires, Argentina
Registered: 2005-11-19
Posts: 4

Re: [archived] ptv_if

Hello Borisch,
nice Afro!
i am trying to implement this plugin with no succes. i am using another plugin to manage events and a third plugin to get a variable from URL could you help me??
i have this code in a form where i list events
first 4 lines are just for debugging

<code>—————————————————————<br>
<txp:chs_urlvar_get var=‘dia’/><br> // gets variable dia froms URL
<txp:jmc_event_time php_date=‘jnY’ /><br> // gets each event day in the format DDMMYY
—————————————————————<br></code>

so i am trying to filter events from a day:

<code><txp:ptv_condition>
<txp:ptv_if leftarg=”<txp:chs_urlvar_get var=‘dia’/>” condition=“eq” rightarg=”<txp:jmc_event_time php_date=‘jnY’ />”>
<h1>something</h1> </txp:ptv_if>
</txp:ptv_condition></code>

and i have this output:

—————————————————————<br>
18112005
18112005<br>
—————————————————————<br>
18112005 <br>
—————————————————————<br>
18112005
18112005<br>
—————————————————————<br>
18112005 <br>
—————————————————————<br>
18112005
18112005<br>
—————————————————————<br>
18112005 <br>
—————————————————————<br>
18112005
19112005<br>
—————————————————————<br>
19112005<br>
<br>

as i am not a coding expert i can figure out what i am doing wrong. i have seen your example working with pluggins but cant understand how to use it in this scenario.

Thanks in Advance!!

gb

Last edited by gb (2005-11-22 01:39:12)

Offline

#7 2005-11-22 03:13:52

Borisch
Archived Plugin Author
From: Sweden
Registered: 2004-05-30
Posts: 15
Website

Re: [archived] ptv_if

Hi there.

Thanks for the compliment =)

It’s been a long time since I wrote the plugin and a long time since I coded anything =)
I don’t have a lot of spare time until the beginning of December so a longer answer will have to wait.

The problem is that you’re calling two functions of which neither returns booleans and both need named parameters.

I think that this should be doable in the following way:

&lt; txp:ptv_condition &gt;
&lt; txp:ptv_if leftarg=“chs_urlvar_get(($inatts[‘var’]=‘dia’))” condition=“eq” rightarg=“jmc_event_time(($inatts[‘php_date’]=‘jnY’))” &gt;
&lt; h1 &gt; Do something &lt; /h1 &gt;
&lt; /txp:ptv_if &gt;
&lt; txp:ptv_else &gt; Do something else &lt; /txp:ptv_else &gt;
&lt; /txp:ptv_condition &gt;

If it works, spiffy, if not, spank me.
I’ll return again as I said and will probably have a look at the plugin. I have to lake a look at where textpattern is now (in the latest version) see if my plugin is needed or not and if sao, rewrite it to make it a tad simpler and more functional.

Cheers!

P.s. sorry bout the lousy formatting. I can never get the hang of this forumformatting thing =) I managed to figure it out last time, but it’s been to long since.

Last edited by Borisch (2005-11-22 03:28:20)


Instead of conquering the world, I’m collecting it in my attic.

Offline

#8 2006-06-25 21:59:11

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: [archived] ptv_if

hello
been a while since this thread saw any action… are you still there Borisch?

I was wondering if it’s possible to use this plugin to test for category values…
In your example you do it by testing the the mdm_if_category plugin, which is now obselete and unavailable…

<code><txp:ptv_condition> <txp:ptv_if plugin=“mdm_if_category” category=“Alpha”> Content specific to Alpha category </txp:ptv_if> <txp:ptv_else> Content for everything else </txp:ptv_if>
</txp:ptv_condition></code>

How could I acheive the same result without that plugin?

many thanks
Stu

Offline

#9 2006-06-26 22:47:04

Borisch
Archived Plugin Author
From: Sweden
Registered: 2004-05-30
Posts: 15
Website

Re: [archived] ptv_if

I’m still here :)

In order to answer your question I really have to get reaquainted to TP as the last version I saw was the one I wrote the plugin for (some 15 months ago). No worries though. As my wife to be has been bugging me to redo her site for some time and I seem to have a week or two of spare time this summer, this will probably be soon.

As is I can only say that the ptv_if won’t do it by itself. If you have a variable or function that returns category name, it should be doable by a left/right comparison though.

[Edit]I thought that conditions was one of the things they were planning to add in versions to come back when I had just written this? Hasn’t that been implemented yet? (Just curious)

Last edited by Borisch (2006-06-26 22:48:33)


Instead of conquering the world, I’m collecting it in my attic.

Offline

#10 2006-06-26 22:54:03

benbruce
Plugin Author
Registered: 2006-01-13
Posts: 328
Website

Re: [archived] ptv_if

I might not understand what you want, but does the TXP tag “if_category” help at all? Here’s the page in the Textbook.

<code>
<txp:if_category> …your content here…<txp:else />…default option… </txp:if_category>
</code>

Offline

#11 2006-06-27 08:04:08

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: [archived] ptv_if

@ benbruce
thanks for the suggestion – <code>if_category</code> is useful in most cases, but my problem is that in I need to output two different forms from my category-list page template
1] where the category value is one of four predefined, named, possibilites
2] where the category value is anything else (except null)

@ Borisch
welcome back!

If you have a variable or function that returns category name, it should be doable by a left/right comparison though.

when you say variable or function does it have to be a php variable or function, or can you test for a textpattern one?
I’m not sure how I could write it to test for the category value… I’m a php baby :)

This is what I’d like to write, but it gives an error.

<code><txp:ptv_condition></code>
<code> <txp:ptv_if leftarg=“category” condition=”==” rightarg=“cats”></code>
<code> Content specific to cats</code>
<code> </txp:ptv_if></code>
<code> <txp:ptv_else_if leftarg=“category” condition=”==” rightarg=“dogs”></code>
<code> Content specific to dogs</code>
<code> </txp:ptv_if></code>
<code> <txp:ptv_else_if leftarg=“category” condition=”==” rightarg=“birds”></code>
<code> Content specific to birds</code>
<code> </txp:ptv_if></code>
<code> <txp:ptv_else_if leftarg=“category” condition=”==” rightarg=“fish”></code>
<code> Content specific to birds</code>
<code> </txp:ptv_if></code>
<code> <txp:ptv_else></code>
<code> this is still a category list, but it’s not one of the named ones, so I can output another form for ‘unnamed’ categories here</code>
<code> </txp:ptv_if></code>
<code></txp:ptv_condition></code>
<code> </code>

also, could there be a compatibility problem with the latest Txp version (4.0.3) ?
even if I copy your example into my page template I get this error:
<code>Parse error: syntax error, unexpected T_LNUMBER in /admin/lib/txplib_misc.php(459) : eval()’d code(34) : eval()’d code on line 1</code>

any advice appreciated!
Stu

Offline

#12 2008-03-15 23:11:54

sirNemanjapro
Member
From: Čačak, Serbia
Registered: 2007-12-08
Posts: 59
Website

Re: [archived] ptv_if

The link for the file is not working! :(


“… they were enterprising voyages…” – Mr. Spock ( from Spock vs. Q )

Offline

  1. Index
  2. » Archives
  3. » [archived] ptv_if

Board footer

Powered by FluxBB