Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#97 2008-08-17 16:49:03

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,256

Re: smd_if: Generic multiple if condition tests

You might try if chs_if_urlvar still works with 4.0.7.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#98 2008-09-08 20:11:25

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_if: Generic multiple if condition tests

Just wonder, is it possible to add “core’s” conditions, like:

  • if_article_list \ if_individual_article
  • check the value of @<txp:variable name=“xx” />

Because sometime I need to check if it’s if_article_list and <txp:variable /> has some value, or matchs some params. It would be nice adding :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#99 2008-09-08 22:07:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,523
Website GitHub

Re: smd_if: Generic multiple if condition tests

the_ghost wrote:

Just wonder, is it possible to add “core’s” conditions <snip>

txp:variable, I agree would be useful and is indeed very simple to add. Will be in the next official version.

The result of if_article_list / if_individual_article are much trickier because they aren’t parsed by the plugin. Even if they were, consider this fictional tag syntax:

<txp:smd_if field='<txp:if_article_list />' operator="istrue">
  // In a list
</txp:smd_if>

From the plugin’s perspective, if you are viewing an article it sees this:

if (@nothing@ == true) {
  // Gives a syntax error
}

because the output of <txp:if_article_list /> is empty / nada / nothing in an article context. Thus, parsing this is not easy.

For now, can you get away with a bit of nesting:

<txp:if_article_list>
  <txp:if_variable name="my_var" value='<txp:php>echo gps('my_url_var');</txp:php>'>
    // Yay! Article list AND variable matches URL variable
  </txp:if_variable>
</txp:if_article_list>

Only very simple equality tests can be performed this way so if you desperately need the txp:variable functionality, make the following changes to the plugin code…

Change line 2 to read:

	global $thisarticle, $pretext, $thisfile, $thislink, $variable;

Line 126 (immediately before } else if ($fldParts[0] == "urlvar") {) :

			} else if ($fldParts[0] == "txpvar") {
				if (count($fldParts) == 2) {
					$fld = '$variable["'.$fldParts[1].'"]';
				}

New line 163 (immediately before } else if (strpos($valParts[0], "?") === 0) {) :

			} else if ($valParts[0] == "txpvar") {
				if (count($valParts) == 2) {
					$val = (isset($variable[$valParts[1]]) && $variable[$valParts[1]] != "") ? '$variable["'.$valParts[1].'"]' : doQuote(str_replace('"', '\"', $valParts[1]));
				}

That should work but it’s not very thoroughly tested.


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

Offline

#100 2008-09-10 20:58:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,523
Website GitHub

Re: smd_if: Generic multiple if condition tests

New major revision out in the guise of v0.7 [ compressed ]

Key features:

  • New operators in and notin so you can check a list of things against a single field
  • New attribute list_delim (for use with in and notin)
  • Support for <txp:variable /> so you can now directly compare multiple txp vars without having to embed the tags. Use txpvar:my_var syntax
  • Added replacement tags, a bit like in smd_gallery. Now all fields and values that you reference in the tag become available in the containing block so you can display them. Might sound useless, but check out Example 8 in the help for a real-world use case
  • Support built in for conditionals in the proposed image context (tag syntax still under review ready for core submission early in the 4.0.8 dev cycle)
  • Bug fix for the problem visualpeople had with empty custom fields

Take it for a spin round the block and toot the horn if you spot a CTA on the journey…


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

Offline

#101 2008-09-19 15:32:53

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: smd_if: Generic multiple if condition tests

Thank you for the update. Works ok for me.

Offline

#102 2008-09-25 12:55:27

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hello,

I have one question.
I have a url like this : http://test.tamarawobben.nl/?c=jaar1&month=2005-10
Now i wonder if with this plugin i can count the articles which are in this category and in this month.

Roelof

Offline

#103 2008-09-25 18:32:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,523
Website GitHub

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Now i wonder if with this plugin i can count the articles which are in this category and in this month.

I don’t think so. This is a conditional plugin that takes action if one or more tests is true or not. Counting stuff is best done with another tool. Of course, once you get the result from whatever method you use to count things, then smd_if can take action if it is greater than/less than/equal to a certain value or a certain field.

Does that clarify your question, or have I misunderstood your intention?


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

Offline

#104 2008-09-25 19:00:25

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

no, it clarify my question.

I try to find a way to make a pagination as i want it.
With this plugin i can make it but then i make some double work.
Everytime i have a month i have to type page2 etc again.
So back to the drawing table.

Roelof

Offline

#105 2008-09-27 08:42:25

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hello,

Can i nest this tag.
I have this problem.
I think i can use this plugin to make a sort of pagination.

I have this problem.

When the month has 1 page , there will be no paging.
When a month has 2 or more pages, there will be paging.
And i have to mark the current page.

So i have this :

<txp:smd_if field= custom2 operator=“qt” value=2> <txp:smd_if field=custom1 operator=“qt” value=1> the url for page 1 (current) the url for page 2 else the url for page 1 the url for page 2 (current)
</txp:smd_if>
</txp:smd_if>

Can this work ?

Roelof

Sorry for the inconvience, but this doesn’t work.
In the url i can tell txp that i want to see another page but TXP doesn’t know what that page is.

Last edited by roelof (2008-09-27 12:05:55)

Offline

#106 2008-09-28 06:24:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,523
Website GitHub

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Can i nest this tag.

Under TXP 4.0.6, no. It is governed by the same rules as every other tag. Under TXP 4.0.7 or later, yes, but there are problems with your smd_if syntax: the operator is "gt" (greater than) not "qt", and the ‘else’ needs to be a <txp:else/>. Also bear in mind that you can only use the words ‘custom1’ and ‘custom2’ if you have not renamed the fields in Admin->Preferences->Advanced, otherwise you must use whatever names you have assigned. And as a matter of style, the attribute values should all be in double quotes as (I think) this will be enforced from TXP 4.0.7 onwards.

But I still don’t quite understand what you are trying to achieve with this approach. I’ve seen your other posts on this topic and I’m still a bit confused since you appear to be trying to use custom1 and custom2 to indicate how many pages are in a month. That means you have to hard-code the values into each article, which is definitely not the way to do it! Does the rsx_page_number plugin help you?


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

Offline

#107 2008-09-28 10:15:57

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Whay i trying to achieve is a pagination like this http://voorbeeld.tamarawobben.nl

Im now trying to do it with rsx_page_number but there i can’t get the url right.

Roelof

Offline

#108 2008-09-30 19:21:06

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_if: Generic multiple if condition tests

Thanks for this great plugin.

But I have one problem. Whenever I’m trying to use the begins operator I’m getting this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '$' in /path/to/textpattern/lib/txplib_misc.php(574) : eval()'d code(228) : eval()'d code on line 3

The way I’m trying to use the begins operator is like this:

<txp:smd_if field="body" operator="begins" value="Posted by">
...
</txp:smd_if>

I don’t know if I’m doing something wrong?

Offline

Board footer

Powered by FluxBB