Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#265 2009-11-19 20:09:44

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: smd_if: Generic multiple if condition tests

I use txp:output_form to reference the main menu from every page template in my site. I was just working on the error_default page and realized that the menu code below wasn’t displaying section links like it does everywhere else in the site:

<txp:section name="nameofsection" link="1" title="1" wraptag="h2" <txp:smd_if field="section,parent" operator="eq,contains" value="nameofsection,nameofsection" logic="or">class="selected"</txp:smd_if> />
<txp:section name="anothernameofsection" link="1" title="1" wraptag="h2" <txp:smd_if field="section,parent" operator="eq,contains" value="anothernameofsection,anothernameofsection" logic="or">class="selected"</txp:smd_if> />

I ended up having to place the menu code directly in the error_default page and remove the smd_if part from each txp:section tag to get it to work. I just thought it was kind of strange that smd_if would break the txp:section tag only on error_pages and thought I’d mention it here.

Offline

#266 2009-11-25 04:07:29

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

I have the following:

<txp:smd_if field="urlvar:countries" operator="in" value="a-b/c-e/f-j/k-m/n-r/s/t-z">
    <txp:article listform="article_list" country_range="{smd_if_countries}" limit="1" sort="title" />
</txp:smd_if>

which works like a charm. But I was wondering if there was a way to replace a-b/c-e/f-j/k-m/n-r/s/t-z with a query that tests for all the values of the custom field name country_range and then places those results in the value attribute of the <txp:smd_if> tag.

Such that the first line of code above becomes:

<txp:smd_if field="urlvar:countries" operator="in" value="[results of query here, separated by a slash]">

“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#267 2009-11-25 07:26:36

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: smd_if: Generic multiple if condition tests

speeke wrote:

<txp:smd_if field=“urlvar:countries” operator=“in” value=”[results of query here, separated by a slash]”>

Could you use smd_query and tags within tags?


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#268 2009-11-25 20:49:52

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

MattD wrote:

Could you use smd_query and tags within tags?

I was thinking along those lines, but I can’t see how to create a query that runs through all the values of the column custom_13, and then outputs them in a string: a-b/c-e/f-j/k-m/n-r/s/t-z where / is the separator (custom_13 contains values in the format: a-b).

I’ve started with this:

<txp:smd_query query="SELECT DISTINCT custom_13 FROM textpattern WHERE section = 'section_name' AND status = 4 GROUP BY custom_13">

but after that I’m in the dark. I’m looking to create a variable that holds the complete string.


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#269 2009-11-25 21:10:57

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: smd_if: Generic multiple if condition tests

not tested but this should work if I’m reading the plugin instructions correctly. I did test the smd_query part with a slightly different query.

<txp:variable name="fieldValues" value='<txp:smd_query query="SELECT DISTINCT custom_13 FROM textpattern WHERE section = 'section_name' AND status = 4 GROUP BY custom_13">{custom_13}/</txp:smd_query>'/>

Last edited by MattD (2009-11-25 21:11:34)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#270 2009-11-25 21:49:46

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

I’ve tried this query, but am not getting any output. No errors either :/


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#271 2009-11-25 22:34:51

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: smd_if: Generic multiple if condition tests

If you try it with just the smd_if you should see the output on the page. I tried it with this query to confirm it returned the results I expected.

<txp:smd_query query="SELECT DISTINCT custom_1 FROM textpattern WHERE status = 4 and custom_1 is not null and custom_1 != '' GROUP BY custom_1">{custom_1}/</txp:smd_query>

Giving me the following results which is a list of longitudes i have in the custom_1 field.

34.61399647590717/36.456207/36.6097641273077/36.618253/36.63329984895536/36.6439807/36.65953737334756/36.661120979806085/36.68050030625411/36.680561/36.69072153677273/36.69099683732502/37.77833010785869/

The only issue I see is removing the last delimiter.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#272 2009-11-26 00:55:52

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

Yes, the smd_if tag works fine. But I can’t seem to get it to work within the variable tag. No matter, I’ll try a different approach.


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#273 2009-11-26 05:17:36

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: smd_if: Generic multiple if condition tests

You’re right. When using smd_query inside txp:variable I get an error.

Tag error: <txp:smd_query query="SELECT DISTINCT custom_1 FROM textpattern WHERE status = 4 and custom_1 is not null and custom_1 != ' GROUP BY custom_1"> ->  Textpattern Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' GROUP BY custom_1' at line 1
SELECT DISTINCT custom_1 FROM textpattern WHERE status = 4 and custom_1 is not null and custom_1 != ' GROUP BY custom_1
textpattern/lib/txplib_misc.php(594) : eval()'d code:69 getRows()  on line 85
textpattern/lib/txplib_db.php:85 trigger_error()
textpattern/lib/txplib_db.php:272 safe_query()
textpattern/lib/txplib_misc.php(594) : eval()'d code:69 getRows()
textpattern/publish.php:1146 smd_query()
textpattern/publish.php:1081 processTags()
textpattern/lib/txplib_misc.php:977 parse()
textpattern/publish.php:1146 splat()
textpattern/publish.php:1068 processTags()
textpattern/publish.php:506 parse()
index.php:45 textpattern()

My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#274 2009-11-26 08:20:37

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

Re: smd_if: Generic multiple if condition tests

MattD wrote:

You’re right. When using smd_query inside txp:variable I get an error.

That’s ‘cos of the double single quote '' in the query ending the variable definition.

EDIT: Ignore my stupid smd_each ramblings; didn’t read the problem properly. How about this using the smd_query break attribute to fix the trailing slash problem and using txp:variable as a container to bypass all the quoting issues:

<txp:variable name="fieldValues"><txp:smd_query query="SELECT DISTINCT custom_13 FROM textpattern WHERE status = 4 and custom_13 is not null and custom_13 != '' GROUP BY custom_13" break="/">{custom_13}</txp:smd_query></txp:variable>

Any good if you plug ?fieldValues into your smd_if?

Last edited by Bloke (2009-11-26 08:29:24)


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

#275 2009-11-26 08:38:09

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: smd_if: Generic multiple if condition tests

Ah, and I had tested it earlier without the !='' which is why I expected it to work.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#276 2009-11-26 09:51:27

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

@Bloke, that does the trick. Many thanks to you. There’s just no end to the possibilities!!!

PS: Thanks also to MattD :)


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

Board footer

Powered by FluxBB