Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#49 2008-02-21 23:50:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

photonomad wrote:

if the custom field does not contain/begin with “http://” , then I do not want smd_if to output that field.

Unless I’ve totally misunderstood what you’re trying to do, can you swap the logic round so that it becomes: if the custom field does contain/begin with “http://” then you do want to output the field?

Or can you make use of <txp:else /> to test for the positive case and put your code in the else branch to “negate” the logic? i.e.

<txp:smd_if field="custom1" operator="begins" value="http://">
// output the field
<txp:else />
// don't output the field
</txp:smd_if>

(in fact the else might not even be necessary if you don’t want to take any action if the field is empty)

If I’ve got the wrong end of the stick, hammer the message home in another post and I might get it :-)


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

#50 2008-02-26 17:17:20

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

Re: smd_if: Generic multiple if condition tests

Hello

Sorry to be a numpty, but I can’t get this plugin to do what I hoped. I suspect the problem is with my implementation rather than the plugin.

On my homepage I have a simple list of permalinks to articles pulled from across the site. I’m trying to test for the parent category of each article’s category1 value and append some text to the link where appropriate.

The relevant bit of the category structure is
  • TRAVEL
    • Croatia (0)
    • France (0)
    • Greece (0)
    • etc

The site admin can add new countries as subcategories as they arise, so I can’t hard-code a test for the actual value of category1 (the parent TRAVEL category is just a guide to keep the category menu tidy – it won’t ever be assigned itself).

This is what I have in my article form…

<txp:smd_if field="parent" operator="begins" value="TRAVEL"> (Travel review)</txp:smd_if>

Is the problem that this isn’t being used in a category page? I spose I’m actually trying to test for the article_category rather than the global one. Hope that makes sense.

many thanks
Stu

Offline

#51 2008-02-26 19:09:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

pieman wrote:

Is the problem that this isn’t being used in a category page?

Yep, you got it in one. Without any modifiers it tests the global category. Try:

<txp:smd_if field="parent:CAT1" operator="begins" value="TRAVEL">(Travel review)</txp:smd_if>


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

#52 2008-02-26 21:11:54

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

Re: smd_if: Generic multiple if condition tests

Cov legend
:)

Offline

#53 2008-02-28 16:05:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,577
Website

Re: smd_if: Generic multiple if condition tests

Stef, I had a problem with <txp:smd_if field="body" operator="isempty" />. It would never recognise body as being empty. The usage scenario is list article with link if content provided, otherwise just list article title and some custom fields.

It may be because I’ve updated a very old site (1.0rc3). At the time I had used swf:if_empty and it too needed an attribute minlength="5" to work.


TXP Builders – finely-crafted code, design and txp

Offline

#54 2008-02-28 16:24:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

jakob wrote:

Stef, I had a problem with <txp:smd_if field="body" operator="isempty" />. It would never recognise body as being empty.

Hmmm, I’ve not tried it myself but I think body is never really empty per se. I think — someone correct me if I’m wrong here — it’s stored with a space in it, even if it looks empty to the naked eye. My guess is the plugin doesn’t deem this “empty” enough to make the comparison pass the test. Try switching debug on in the plugin and see if it gives any clues (it may even have <p></p> in it, which looks empty to us but not to the plugin).

Two things we could do:

1. Instead of isempty, try operator="eq" value=" "
2. I could add to the list of things that are considered empty

In the short term, try (1) and let me know how it goes. I’ll look into the 2nd one, probably not till next week though as I’ve got a site that’s desperately being fixed.

Last edited by Bloke (2008-10-01 09:59:16)


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

#55 2008-02-28 17:02:16

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,577
Website

Re: smd_if: Generic multiple if condition tests

Thanks for the rapid reply!

but I think body is never really empty per se. I think — someone correct me if I’m wrong here — it’s stored with a in it, even if it looks empty to the naked eye.

Yes, that’s the problem swf_ifempty had.

on 1) sorry, no luck with 1

looking in the db with phpmyadmin, body appears empty (to the eye), body_html looks like it has two new lines and a space in it. debug just says [<txp:smd_if field="body" operator="isempty">: false] (same for the other alternative).

re 2) yes, I guess you need to test for more than isset, perhaps something with trim analog to txp:if_excerpt (I’m guessing the same problem will apply to the excerpt as well as the body.


TXP Builders – finely-crafted code, design and txp

Offline

#56 2008-02-28 17:13:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

jakob wrote:

on 1) sorry, no luck with 1

Humbug, but I just noticed that the forum ate the &# 160; (gah, had to force it with a space!). Try the entity number, just out of curiosity.

re 2) yes, I guess you need to test for more than isset, perhaps something with trim analog to txp:if_excerpt (I’m guessing the same problem will apply to the excerpt as well as the body.

Yep, ok. Please report back on how the etntity thing goes but I’ll look into fixing it in the near future anyway. Thanks for letting me know about this problem.

Last edited by Bloke (2008-02-28 17:14:09)


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

#57 2008-03-12 12:51:26

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

Found strange behaviour of smd_if inside chh_if_data:

This code:

<txp:chh_if_data>
<txp:smd_if field="parent" value="any_string">4</txp:smd_if>
</txp:chh_if_data>

Produces this in tagtrace:

<txp:chh_if_data>
	[<txp:chh_if_data>: true]
	<txp:smd_if field="parent" value="any_string">
		[SQL (0,000924): select lft as l, rgt as r from uro_txp_category as txp_category where name='polyanka' and type = 'article']
		[SQL (0,000905): select * from uro_txp_category as txp_category where lft <= 197 and rgt >= 198 and type = 'article' order by lft asc]
		[<txp:smd_if field="parent" value="any_string">: false]
	</txp:smd_if>
	[<txp:chh_if_data>: false]
</txp:chh_if_data>

Maybe smd_if triggers chh_if_data because of some whitespace output?


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

#58 2008-03-12 14:13:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

the_ghost wrote:

Maybe smd_if triggers chh_if_data because of some whitespace output?

Hmmm, in theory it shouldn’t do, but I will check this with some tests later. Thanks for bringing it to my attention.


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

#59 2008-05-16 15:53:01

Ruhh
Member
From: dakota dunes
Registered: 2008-01-20
Posts: 305

Re: smd_if: Generic multiple if condition tests

I was just looking at this. Now I have a question. I have a PHP include to a ask and answer script inside an article that is within a section and that script have pagination. Upon clicking on a page number, it goes to the script’s index page. How can I use smd_if to make the page numbers clickable to the article’s index page along with the page number consisting of the continued contents?

This is what I have:

<txp:smd_if field="section, title" operator="eq" value="index.php?page=1&x=">
<txp:an7_filter><txp:php>include('http://domain.com/ask/index.php?page=1&x=');</txp:php></txp:an7_filter>
<txp:else />
<txp:an7_filter><txp:php>include('http://domain.com/ask/index.php');</txp:php></txp:an7_filter>
</txp:smd_if>

In that case on page 1, I don’t see the continued contents. It still shows the first page.

Last edited by Ruhh (2008-05-16 16:10:29)


<txp:Ruhh />

Offline

#60 2008-05-16 16:26:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: smd_if: Generic multiple if condition tests

Ruhh wrote:

How can I use smd_if to make the page numbers clickable to the article’s index page along with the page number consisting of the continued contents?

How about:

<txp:smd_if field="urlvar:page" operator="isused">
  <txp:an7_filter>
    <txp:php>
      include('http://domain.com/ask/index.php?page=' .$_GET['page']. '&x=');
    </txp:php>
  </txp:an7_filter>
<txp:else />
  <txp:an7_filter><txp:php>include('http://domain.com/ask/index.php');</txp:php></txp:an7_filter>
</txp:smd_if>

Not sure if that’ll quite work; you might have to tweak stuff.


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

Board footer

Powered by FluxBB