Textpattern Forum

You are not logged in. Register | Login | Help

#91 2008-08-15 17:46:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,802
Website

Re: smd_if: Generic multiple if condition tests

Hmmm, if this is in an article, have you set it to ignore Textile? Putting PHP tags in a textiled article sometimes gives freaky unexpected results like that, in my experience.

EDIT: also, the dangling single quote in the last line :-)

Last edited by Bloke (2008-08-15 17:47:39)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#92 2008-08-15 17:53:36

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

Re: smd_if: Generic multiple if condition tests

Well I did insert notextile. I also insert another before the added part but I still get an error.

OH. I need to add in another quote, the ending to the first quote?

Now working :)

Last edited by Ruhh (2008-08-15 18:46:11)


<txp:Ruhh />

Offline

#93 2008-08-15 19:02:29

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

Re: smd_if: Generic multiple if condition tests

Err! I don’t think I’m happy with the result.

I don’t know if it has to do with the version of TXP but I put in two else tags along with two smd_if tags. Is that possible?

Here is my code:

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

the a page have no errors but the numbered page gets this error:

Notice: Undefined index:  page  on line 1

Last edited by Ruhh (2008-08-15 19:06:40)


<txp:Ruhh />

Offline

#94 2008-08-15 19:05:44

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
Website

Re: smd_if: Generic multiple if condition tests

No, it isn’t possible to nest identical tags in 4.0.6. It will be possible in next version.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#95 2008-08-15 19:07:42

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

Re: smd_if: Generic multiple if condition tests

Ah.. okay. Is there a download of 4.0.7 available?

I got both parts to work by using chh_if_data tags.

Last edited by Ruhh (2008-08-15 19:13:26)


<txp:Ruhh />

Offline

#96 2008-08-16 12:05:13

ultramega
Member
Registered: 2006-02-26
Posts: 221

Re: smd_if: Generic multiple if condition tests

I made some time ago an alternative article listing. User can select to list articles with or without article image thumbs. No I’m in need to offer second textlist, this time sorted and titled by data in custom field. I don’t currently have access to dev machine, but obviously this wont be work – because of one smd_if inside other?

smd_if urlvar textonly = yes
     |
    show textlist, form = article title-based listing 
txp:else
     | 
     smd_if urlvar textonly_v2 = yes
                  | 
                  show textlist, form = custom1 as link, sortby = custom1
     /smd_if
     |
txp:else
           | 
           normal list with images
/smd_if

Hmm… any ideas? Wouldn’t mind to build extra-page with article custom, if it is avoidable.

Offline

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

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 3,009

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: 5,802
Website

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.

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: 5,802
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB