Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2008-01-15 02:07:54

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

Re: smd_if: Generic multiple if condition tests

Bug fix alert: v0.51 (compressed) addresses the syntax error when using defined/undefined with case_sensitive=“0” and also makes more distinction between defined/undefined and isused/isempty. See Example 5 in the help for more.


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

#38 2008-01-15 19:05:37

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: smd_if: Generic multiple if condition tests

I have a feeling this plugin could solve the problem that is making me rip out my non-existent hair. Here goes…

I am having a client insert an URL of a resource inside four custom field (depending on how much he needs, it can be one, it can be all four) that is either an image – or a flash object (.swf). He is inserting ONLY the URL, not html (because he doesn’t like HTML). Somehow I need to know what the file is, so I can output the appropriate code – img src… or object…

Now, the first thing I am doing is that I’m surrounding the divs that hold the file with if_custom_field (so TXP doesn’t output them if nothing is entered), but what I can’t do is know which file is it so I can feed that URL (the value of the custom field) into appropriate HTML. Here’s the code:

          <txp:if_custom_field name="projecten_item_3"><div class="media invisible">
            <img src="<txp:custom_field name="projecten_item_3" />" alt="" />
          </div></txp:if_custom_field>

See how it’s locked with an img? Basically now it’s impossible to insert the flash movie into the page because the URL will be fed in to the img element. For that purpose – I have another custom field named file_type, and I have tried something like this:

         <txp:if_custom_field name="projecten_item_3"><div class="media invisible">
            <txp:if_custom_field name="file_type" val="swf">...flash stuff here
            <txp:else />
            <img src="<txp:custom_field name="projecten_item_3" />" alt="" />
            </txp:if_custom_field>
          </div></txp:if_custom_field>

But I can’t nest if_custom_field tags. Is there maybe a way this plugin can check for values of both these custom fields and output appropriate code?

Offline

#39 2008-01-15 20:41:03

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

Re: smd_if: Generic multiple if condition tests

draganbabic wrote:

I am having a client insert an URL of a resource inside four custom field… that is either an image – or a flash object (.swf).

Looks like you might be in luck if I’ve understood this correctly. Since swf objects tend to have the least variation in file extension (and assuming the client sticks to a decent naming convention), the easiest thing is to just test the URL directly:

<txp:smd_if "projecten_item_3" operator="contains" value=".swf">
  // Output swf container
<txp:else />
  // Output img container
</txp:smd_if>

And repeat that block for each of your custom fields. Of course, if you wanted to use you “type” custom field you could perhaps do:

<txp:smd_if "file_type, projecten_item_3" operator="eq, isused" value="swf">
  // Output swf container
<txp:else />
  // Output img container
</txp:smd_if>

Depending on whether the client can mix and match img and swf types in a single article depends on whether the file_type custom field is of any use or not!

Does that help?


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

#40 2008-01-16 09:43:31

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: smd_if: Generic multiple if condition tests

Thank you very much for the response Bloke, but the first code (which seems much simpler to use for both me and the client) always seems to return positive for operator=“contains” value=”.swf” – so it always outputs the swf container. Here’s the code:

         <txp:if_custom_field name="projecten_item_1"><div class="media">
<txp:smd_if "projecten_item_1" operator="contains" value=".swf">
            <object type="application/x-shockwave-flash"
data="<txp:custom_field name="projecten_item_1" />" 
width="650" height="180">
              <param name="movie" 
value="<txp:custom_field name="projecten_item_1" />" />
            </object>
<txp:else />
            <img src="<txp:custom_field name="projecten_item_1" />" alt="" />
          </txp:smd_if></div></txp:if_custom_field>
          <txp:if_custom_field name="projecten_item_2"><div class="media invisible">
<txp:smd_if "projecten_item_2" operator="contains" value=".swf">
            <object type="application/x-shockwave-flash"
data="<txp:custom_field name="projecten_item_2" />" 
width="650" height="180">
              <param name="movie" 
value="<txp:custom_field name="projecten_item_2" />" />
            </object>
<txp:else />
            <img src="<txp:custom_field name="projecten_item_2" />" alt="" />
          </txp:smd_if></div></txp:if_custom_field>
<!-- I have two more of these since I have four projecten_item_x custom fields --> 

Note that it doesn’t work when I remove the if_custom_field conditionals that are wrapping the smd_if as well. Any thoughts?

EDIT:

Value for projecten_item_1 was http://mysite.com/dir/images/SKP0701_1.jpg
Value for projecten_item_2 was http://mysite.com/dir/files/SKP07.swf

Last edited by draganbabic (2008-01-16 09:44:54)

Offline

#41 2008-01-16 18:19:23

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: smd_if: Generic multiple if condition tests

Ignore my desperate cry for help. :)

The problem was within <txp:smd_if field=“projecten_item_1” operator=“contains” value=”.swf”>

Offline

#42 2008-01-16 21:10:56

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

Re: smd_if: Generic multiple if condition tests

Well spotted! Glad it works now; I scratched my head for a bit and wondered if the plugin was broken… phew!


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

#43 2008-01-17 19:21:38

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: smd_if: Generic multiple if condition tests

Hi Stef, just wanted to say a huge thank you for this amazing plugin – it adds a whole new dimension to what can be done with TxP.

Last edited by lee (2008-01-17 19:22:01)

Offline

#44 2008-02-20 15:40:46

maxvoltar
Member
From: Machelen, Belgium
Registered: 2007-08-16
Posts: 76
Website

Re: smd_if: Generic multiple if condition tests

Ok I got a little problem:

I’m trying to build a custom archive. So far, what I’ve achieved, is url’s looking like this: http://www.madebyelephant.com/blog/?archive=2008-02

Now, how can I check if the ?archive= part is in the url? <txp:smd_if field="urlvar:archive"> made my template go bonkers…

EDIT

Ok I read through this thread, and changed my code to the following:

<txp:smd_if field="urlvar:archive" operator="defined" value=",">
	<p>Success!</p>
<txp:else />
	[Display the default]
</txp:smd_if>

The problem is it gives me a blank page…

EDIT 2

I am a complete moron. Forgot a <txp:else /> somewhere else on the page…

Move on please :-)

Last edited by maxvoltar (2008-02-20 16:14:13)


Textpattern projects: Maxvoltar, Made by Elephant, Twunch

Offline

#45 2008-02-20 20:55:18

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

Re: smd_if: Generic multiple if condition tests

maxvoltar wrote:

Hi, sorry I didn’t get to this earlier. Sounds like you got it sorted without me, though :-)

changed my code to the following: <txp:smd_if field=“urlvar:archive” operator=“defined” value=”,”> …

fwiw, in the latest version you shouldn’t need the value attribute in this situation as the plugin’s defaults are a bit more sensible based on the operators you give it. Since defined doesn’t require a value and it’s the only operator in your test, you can safely omit the value.

Last edited by Bloke (2008-02-20 20:57:03)


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

#46 2008-02-20 21:55:29

maxvoltar
Member
From: Machelen, Belgium
Registered: 2007-08-16
Posts: 76
Website

Re: smd_if: Generic multiple if condition tests

@Bloke: I wrote an article about your plugin (and, how you can use it to create your own archives): http://www.madebyelephant.com/blog/creating-archives-in-textpattern

Last edited by maxvoltar (2008-02-20 21:55:45)


Textpattern projects: Maxvoltar, Made by Elephant, Twunch

Offline

#47 2008-02-20 21:58:23

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

Re: smd_if: Generic multiple if condition tests

Nice one, thanks for sharing the tip :-)


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

#48 2008-02-21 23:30:33

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

Re: smd_if: Generic multiple if condition tests

This is a wonderful plugin!

One question: I am using one of my custom fields for a URL and if the custom field does not contain/begin with “http://” , then I do not want smd_if to output that field. I can’t find an operator that tests for either “does not contain” or “does not begin with”

I would use isempty or undefined, but the person who will be using the site is not super web-savvy and there is a possibility she will enter a URL without the requisite “http://”

Is there a way to do this with the existing plugin or would this have to be added to the functionality of the plugin?

Thanks!

Offline

Board footer

Powered by FluxBB