Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2008-01-04 23:39:19

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: smd_if: Generic multiple if condition tests

Stef,

I perhaps spoke a little too soon over in the other thread

The site under development is here
I have this code on a page, using your plugin:

<code>
<h2>Factory Night Church – Audio Media</h2>
<br />

<ul> <li><a href=”<txp:site_url />fnc/?sort=title”>Title</a></li>
<li><a href=”<txp:site_url />fnc/?sort=series”>Series</a></li> <li><a href=”<txp:site_url />fnc/?sort=date”>Date</a></li> <li><a href=”<txp:site_url />fnc/?sort=author”>Author</a></li>
</ul>
<txp:smd_if field=“urlvar:sort” operator=“undefined” value=”,”>
<h3>FNC Audio Media – by Title</h3><br />
<txp:article listform=“list_title” limit=“10” form=“default” />
<txp:else />
</txp:smd_if>

<txp:smd_if field=“urlvar:sort” operator=“eq” value=“title,” >
<h3>FNC Audio Media – by Title</h3><br />
<txp:article listform=“list_title” limit=“10” form=“default” />
<txp:else />
</txp:smd_if>

<txp:smd_if field=“urlvar:sort” operator=“eq” value=“date,” >
<h3>FNC Audio Media – by Date</h3><br />
<txp:article listform=“list_date” limit=“10” form=“default” />
<txp:else />
</txp:smd_if>

<txp:smd_if field=“urlvar:sort” operator=“eq” value=“author,” >
<h3>FNC Audio Media – by Speaker</h3><br />
<txp:article listform=“list_author” limit=“10” form=“default” />
<txp:else />
</txp:smd_if>

<txp:smd_if field=“urlvar:sort” operator=“eq” value=“series,” >
<h3>FNC Audio Media – by Series</h3><br />
<txp:article listform=“list_series” limit=“10” form=“default” />
<txp:else />
</txp:smd_if>
</code>

This works beautifully for producing the various lists I wanted.
But when I click on the permlink for a single article in the list, I get this error:

Parse error: syntax error, unexpected T_STRING in /home/.akasha/swac/media.swac.org.au/textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code on line 1
Parse error: syntax error, unexpected T_STRING in /home/.akasha/swac/media.swac.org.au/textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code on line 1

And the page only partially displays (although the source indicates that the article is being displayed/generated by TxP)

Any thoughts on what is going wrong?

Thanks!


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#12 2008-01-05 16:43:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: smd_if: Generic multiple if condition tests

NeilA wrote:

Parse error: syntax error, unexpected T_STRING in /home/.akasha/swac/media.swac.org.au/textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code on line 1

Hi Neil, strange one. Not seen that before with the plugin. I’m trying to replicate it here so I can see what’s causing the error message.

When you say “I have this code on a page” where is the code? Is it in an article in the fnc section, or is it in a form? If so, which form? The default one, or the one assigned to the fnc section? Or on the fnc “page”?

I’ve tried putting the code in the default form and I get a ‘circular reference’ error so I guess it’s not there! I’ll continue poking around and see if I can find anything more, but if you can give me a little more info about how you’ve set it up I can probably work out why it’s falling apart on you.

btw, you may not need the extra commas in the value fields (one value is enough) and you can safely delete the <txp:else /> clauses unless you intend on using them later.

EDIT: Still can’t replicate it here after half an hour or so of trying to break it. Perhaps you might permit me to have a login to your test site? Send me an e-mail if so and I’ll have a poke around.

Last edited by Bloke (2008-01-05 18:26:28)


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

#13 2008-01-05 19:24:48

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: smd_if: Generic multiple if condition tests

Hi Stef,

The code is on a page template (called ‘fnc’). I tend to use separate page templates for each section.
I guess it’s sounding like a clash with something else or even a problem with another plugin?

No problem for a login… on it’s way.

Thanks for the help!

Cheers


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#14 2008-01-05 20:52:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: smd_if: Generic multiple if condition tests

NeilA wrote:

I guess it’s sounding like a clash with something else or even a problem with another plugin?

Hehehe, I wish! Nope, it’s sloppy coding on my part; or at least a few unforeseen whatnots. Many thanks for the login: incredibly helpful.

First things first: your site now behaves. You might want to consider putting <txp:if_article_list> tags around the <h3>s inside each smd_if unless you want the “FNC Audio Media – by blah” to appear in the article itself.

Second things second: it’s a bug in the plugin that has 3 parts, all of which you found in one attempt! :-)

  1. I erroneously ran everything given in the ‘value’ argument through the “is this a field” check. In your case, you want to compare the urlvar “sort” with the word “title”. Unfortunately, “title” is the name of a TXP field so it was really looking at the title of the article and doing the comparison. D’oh!
  2. The “title” in your case is actually a custom field (custom_5). This confused the heck out of me (and probably TXP!) at first because the in-built “title” field gets overwritten by your custom field. If you experience odd behaviour (perhaps next/prev article titles not as you expect) you might want to rename that custom field to something else (e.g. “sermon”?)
  3. The contents of your ‘title’ and ‘series’ custom fields both have single quotes around them which threw my plugin into complete disarray, hence the pair of error messages.

To resolve 1) I’ve changed your local copy of smd_if so that it will only compare the in-built fields if you prefix the value attribute with a “?”. So <txp:smd_if field="urlvar:mythingy" operator="eq" value="?title"> will compare the url variable “mythingy” to the title of the article, but removing the ? will compare “mythingy” to the word “title” (as you originally intended).

I have no idea how to resolve #3 right now, I’ll work on a fix later. For now, that error will appear if any single quotes are lying around in any fields in the comparison. When I find a cure I’ll re-issue the plugin.

Many thanks for the use of your site to track this down, and apologies for the inconvenience. I’ll try and get a fix out tonight or tomorrow. In the meantime you’re good to go with the halfway-fixed plugin in your site.

Last edited by Bloke (2008-01-05 20:56:11)


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

#15 2008-01-06 01:09:28

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: smd_if: Generic multiple if condition tests

Hey Stef,

Glad to know my attempts at setting up TxP were useful to you! :-)
You programmers need twits like me to do things like use single quotes in names, and overwrite program variables! LOL.

Seriously, thanks for your prompt work on it, and for the education it’s been for me – it was no drama giving you a login as the site is not public yet and still very much under construction, and it certainly was no inconvenience…

I will change the name of custom_5 and will also drop the single quotes (I seem to recall them causing problems elsewhere too…).

Cheers


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#16 2008-01-06 03:29:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: smd_if: Generic multiple if condition tests

NeilA wrote:

You programmers need twits like me to do things like use single quotes in names, and overwrite program variables!

Hehehe, we need normal people like you to make us see the blindingly obvious :-)

…will also drop the single quotes (I seem to recall them causing problems elsewhere too…).

Fine by me. The only reason I never spotted it is ‘cos I just don’t use them as a matter of course. Same with spaces. Old programming habit I guess. However, the latest version has better support for quotes insofar as I went the other way: single quotes are fine now to allow for apostrophes in words but double quotes will be converted to alleviate the errors you encountered.

So if you use double quotes in things and encounter stuff that fails to match any more, try not comparing against double quotes, or use a less restrictive comparison such as operator="contains" and search for a known bit within the string.

Try v0.4 (or the compressed version) with the official question-mark-in-value extension/patch mentioned above and more robust quote support. Shout if anything goes sideways, and thanks again for finding the bugs.

Last edited by Bloke (2008-01-06 03:44:50)


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

#17 2008-01-06 13:40:42

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

Hi bloke,
I’ve had one instance where this nice plugin threw up errors that I couldn’t figure. I have very possibly done something silly but thought I’d post just in case.

I’m using the plugin in a form to check whether two custom fields are being used:

<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",,"> <p><a href='<txp:custom_field name="URL" />'><txp:custom_field name="URL_name" /></a></p> </txp:smd_if>

When a relevant article is accessed it returns one of these for each custom field queried (can’t seem to format it):

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” value=”,,” logic=“and”> -> Notice: Undefined index: URL on line 1

textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code:1 unknown()
textpattern/lib/txplib_misc.php(534) : eval()’d code:138 eval()
textpattern/publish.php:963 smd_if()
processtags()
textpattern/publish.php:922 preg_replace_callback()
textpattern/lib/txplib_misc.php:1383 parse()
textpattern/publish.php:782 parse_form()
textpattern/publish.php:808 doarticle()
textpattern/publish.php:509 parsearticles()
textpattern/publish.php:963 article()

the debug goes like this, despite both fields being used:
<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",," logic="and"> [<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",," logic="and">: false] </txp:smd_if>

Any tips much appreciated.
(I have installed v0.4)
Thanks,
Peter

Offline

#18 2008-01-06 14:13:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: smd_if: Generic multiple if condition tests

peterj wrote:

I have very possibly done something silly

Hehe, unlikely, it’ll probably be the code!

I can immediately see one problem that I overlooked: custom field names are always stored in the database in lower case. I’ll fix the code in the next revision so that even if you give upper case names they will be converted to lower case before I ask TXP about them.

To get round it for now, just change to this: field="url, url_name".

But don’t do that just yet because it doesn’t explain the error message: I can’t replicate it here. I’ve named two custom fields the same as yours (same capitalisation too) and used the same tag — incidentally you now don’t need the two commas in the value field if you are wholly using operators that don’t require a value, you can either use value="" or miss it out altogether.

So before you change your field attribute to lower case, would you confirm a few things please:

  1. what sort of stuff is in each of your custom fields (I can guess(!) but want to be sure, post some examples if you can). It may be some odd characters are screwing up my code and I need to check for them
  2. add to your smd_if tag the attribute debug="1" and post the output. Just wanna check it’s comparing the right stuff.

Oh, and your version of TXP, thanks. I’m a bit stumped at the moment but I’ll carry on playing with 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

#19 2008-01-06 14:39:21

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

I’m working to late..
1. URL has no quotes, just something like http://www.theage.com.au/
2. The optional friendly name for the link ie The Age

Idea being if no friendly name is put in then LINK is shown.

Hope that helps.
The plugin is working fine on pages, although I’m having some problems there (I think) with the ‘isused’ operator – not 100% sure yet, will have to go to sleep before I break something,

Peter

Offline

#20 2008-01-06 14:40:17

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

Sorry misread the end of your post, will do as instructed.

Offline

Board footer

Powered by FluxBB