Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#121 2008-10-01 15:03:59

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

Re: smd_if: Generic multiple if condition tests

mapu wrote:

It is stripping out the leading spaces now, but it seems it still doesn’t like the <p><a part of it.

Damn, it’s working for me, but I think I’m using the latest SVN copy of TXP which allows angle brackets in attributes. You’re right it doesn’t work with &lt; entities. Hmmmmmm *ponder* let me think about 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

#122 2008-10-09 14:58:06

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

Some addings:

  • check for php vars, not only servervars or get\post. I meen just $i somewhere in code, and use for it prefix phpvar, for example
  • add modifier to check length of field, like this:
    • <txp:smd_if field="phpvar:my_string" operator="gt:LENGTH" value="5">Long!</txp:smd_if>

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

#123 2008-10-09 19:27:22

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:

Some addings: <snip>

Nice ideas, thanks. Will see what I can do in the next revision.


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

#124 2008-10-12 12:43:55

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

Some addings (ver. 2)

Add attribute var, to use {var} inside condition. For example:
<txp:smd_if field="srvvar:myvar1" var="just_show_attr" operator="gt:LENGTH" value="5">The length is {just_show_attr}</txp:smd_if>
And if srvvar:myvar1 = 8, then we will get The length is 8. It can be useful to simplify code inside conditions.


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

#125 2008-10-12 23:29:17

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

Re: smd_if: Generic multiple if condition tests

Time for an update in the wake of recent great ideas. v0.73 [ zipped ] adds:

  • Support for :NOSPACE on the begins, ends and contains operators (thanks mapu; though it still doesn’t fix your problem I’m afraid)
  • Support for new field type phpvar for comparing arbitrary global PHP variables (thanks the_ghost)
  • Support for testing field lengths (ditto)
  • Two new replacement tags to display the length of matched fields/values (ditto again)

I wasn’t quite sure what you meant in your post above about the var attribute. The new replacement tags — {smd_if_len_myVarName} — show the length of the matched contents in your container. Does that help?

If anyone has any foibles or enhancements to report, you know where I am.


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

#126 2008-10-13 06:24:29

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

Bloke:

I wasn’t quite sure what you meant in your post above about the var attribute.

I described the Idea not so good, as I can see. Ok, let me try again… Let see your Examaple 1, for example (btw, at your site it has 2 line returns in a row too_):

<txp:smd_if field="section, id" var="section_tmp, id"

     operator="begins, gt"
     value="lion, 12">
 <txp:article />
 The section is {section_tmp}, and the id is {id}.
<txp:else />
 <p>Not today, thanks</p>
</txp:smd_if>

So, the idea is to output fields values with a shorthand – not allways it’s posible ot access their values like <txp:section /> or <txp:article_id />. It can be php var, for example, or something else. And since your plugin parse this values, it can (i think) output their values inside condition.

Can this be understandable now? :)

Last edited by the_ghost (2008-10-13 06:31:59)


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

#127 2008-10-13 10:03:00

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

Re: smd_if: Generic multiple if condition tests

the_ghost

OK, I see what you are getting at now. Thanks for clarifying. So, do you not like the {smd_if_varName} syntax introduced in v0.7 and want to rename variables to your own names?

Every value and field you use in the plugin is given an ‘smd_if_’ prefix and is therefore available as a replacement tag. So you can rewrite the example like this:

<txp:smd_if field="section, id" operator="begins, gt" value="lion, 12">
 <txp:article />
 The section is {smd_if_section}, and the id is {smd_if_id}.
<txp:else />
 <p>Not today, thanks</p>
</txp:smd_if>

However, I have just spotted a small bug that I’ve fixed in v0.74 [ zipped ] whereby if you used two or more similar types of fields/values, the replacement tags from early tests would be overwritten by ones from later tests. That’s now fixed and replacement tags have an index number added to them (e.g. the 2nd value is now smd_if_val2).

If I’ve not explained the replacement tags properly in the help (likely!) I can go and try to make it clearer. Does that help or am I still missing your point?


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

#128 2008-10-13 10:57:01

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: smd_if: Generic multiple if condition tests

@Stef: Pls. don’t let users rename variables. Code reading (here) will get too complicated as it is already for me :)

Last edited by merz1 (2008-10-13 10:57:36)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#129 2008-10-13 11:01:00

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

Re: smd_if: Generic multiple if condition tests

merz1 wrote:

Pls. don’t let users rename variables.

As you can probably tell by now, I’m trying to avoid it ;-) It’s bad enough trying to work out what’s going on when using this plugin as it is!


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

#130 2008-10-15 10:55:51

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

Block wrote

Does that help or am I still missing your point?

Now it works brilliantly! I used your plugin with this snippet:

<txp:smd_if field="urlvar:print_id" operator="isnum">
  <txp:variable name="print_id" value="{smd_if_print_id}"/>
<txp:else />
  <txp:variable name="print_id" value="error"/>
</txp:smd_if>

Here are my steps to make printer-frindly version:

  1. Made section print which is using page print (code of page print)
  2. in default form, which renders my articles at site made link to section print with urlvar print_id
    1. <a href="/?s=print&print_id=<txp:article_id />" target="_blank">Print this</a>
  3. That’s all! As result we get html page with a small size and with presentation for printing – no colors, boxes and other stuff..

P.S. Of course, you can make link more “clean”, but this one works with any url_mode setting. Current working example is avaible here But it’s in russian, so look for link Версия для печати at the end of articles and click it.


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

#131 2008-10-24 20:00:14

visualpeople
Member
From: Corvallis, Oregon - USA
Registered: 2005-11-16
Posts: 73
Website

Re: smd_if: Generic multiple if condition tests

Stop me if this is impossible… It seems like I should be able to do it, but I can’t quite get my puny little brain around it.

I want to serve up a random banner ads and I think I can use the smd-trifecta to achieve this. It has to be a random banner ad (thanks smd_random_banner!) but it might be a flash ad, or it might be a .gif image (no problem, thanks to smd_random_text!) but what if there are no ads in either the images or files section? I think smd_if should be able to come to my rescue, but I haven’t been able to get it to work yet…

here’s the code that’s working so far:

<txp:smd_random_text type="string" source="file|image">
<txp:smd_random_banner category="top_horizontal_banner" imgclass="ad" link_in="caption" mode="{smd_rnd_txt}" nv_delim="::" global_params="playerversion::9;width::728;height::90;"/>
</txp:smd_random_text>

I was thinking I need to call a form that lists all of the images in the “top_horizontal_banner” category and then if nothing shows up in that form, then display files… but that’s where I can’t figure out exactly what to do with those results.

Then what happens if there are images with the category “top_horizontal_banner” but no files with the category “top_horizontal_banner”?

Offline

#132 2008-10-31 00:56:44

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

It seems that smd_if turns off case-insensetivity when accessing custom_fields by name. I have custom field named “Podmenu”. I have such code:

<txp:smd_if field="Podmenu,txpvar:ind_art" operator="isnum,eq" value=",1" logic="or" debug="2">

But this allways fires as “false”. When I added debug="2" i saw:

THIS ARTICLE:
array (
  'thisid' => '10',
  'posted' => '1220084884',
  'modified' => '1220178592',
  'annotate' => '0',
  'comments_invite' => '',
  'authorid' => 'admin',
  'title' => 'Подраздел 2',
  'url_title' => 'podrazdel-2',
  'category1' => '',
  'category2' => '',
  'section' => 'okrugi',
  'keywords' => '',
  'article_image' => '',
  'comments_count' => '0',
  'body' => '	<p>lalala</p>',
  'excerpt' => '',
  'override_form' => '',
  'status' => '4',
  'podmenu' => '3', <<<<<<<<<<<
  'file_id' => '',
)

Look at highlighted string – custom_field is written in lowercase.


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

Board footer

Powered by FluxBB