Forum Moderators: coopster & phranque

Message Too Old, No Replies

elseif statements matching categories.

when working with my blog how do i match the include file with the category

         

recordc48

9:47 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



Heres the situation. I am embedding an include file into the bottom center section of my blog. Let's use sports as the example. Let's say the category tree is as follows:

Sports > Baseball > SF Giants

What are the elseif statements needed to do the following? I have tried many different ways and I am not sure how to do it. What would the example code look like?

if category = "SF Giants" then include "giants.txt" or else
if category = "NY Yankees" then include "yankees.txt or else
if category = "AZ Diamondbacks" then include "diamondbacks.txt

Does this make sense?

Then obviously I would want to add something at the end where if there was no match, there would be a default .txt file.

I greatly appreciate any help with this. :)

coopster

10:16 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if (category = "SF Giants") {include "giants.txt"} 
elsif (category = "NY Yankees") {include "yankees.txt"}
elsif (category = "AZ Diamondbacks") {include "diamondbacks.txt"}
else {include "default.txt"}

However, a bare block [perldoc.com] lends itself nicely to this particular case structure.
SWITCH: { 
if (category = "SF Giants") {include "giants.txt"; last SWITCH; }
if (category = "NY Yankees") {include "yankees.txt"; last SWITCH; }
if (category = "AZ Diamondbacks") {include "diamondbacks.txt"; last SWITCH; }
include "default.txt";
}

recordc48

12:01 am on Nov 23, 2004 (gmt 0)

10+ Year Member



Tremendous thanks for the help.

Unfortunately the code is not working. I am messing with it to try different versions to see if it works, but it doesn't. I kept getting errors until I wrote the code this way, and then it at least didn't have errors, but it still didn't work.

{{if category="SF Giants"}} {{include name="giants.txt"}}
{{/if}}
{{if category="NY Yankees"}} {{include name="yankees.txt"}}
{{/if}}
{{if category="AZ Diamondbacks"}} {{include name="diamondbacks.txt"}
{{else}}
{{include name="default.txt"}} {{/if}}

Any ideas on where to go from here? This is fun but at the same time frustrating. I love learning perl, but I am pretty confused sometimes.

I am very appreciative of the help. Thanks!

coopster

3:53 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You said that was example code, so I assumed you meant pseudocode. If you are really trying to execute the code shown here, you need to use variables and functions that exist, for example:
my $category = 'NY Yankees'; 
SWITCH: {
if ($category = "SF Giants") {print "giants!"; last SWITCH; }
if ($category = "NY Yankees") {print "yankees!"; last SWITCH; }
if ($category = "AZ Diamondbacks") {print "diamondbacks!"; last SWITCH; }
print "default!";
}

recordc48

6:43 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



Thanks for all the help coopster. I was finally able to get it to work. I used the following code:

{{if category.label eq "SF Giants"}}
{{include name="giants.txt"}}
{{elsif category.label eq "NY Yankees"}}
{{include name="yankees.txt"}}
{{else}}
{{include name="default.txt"}}
{{/if}}

It ended up being pretty simple when it was all said and done. I thank you for helping me out!