BlogHarbor Home Page
FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  UsergroupsRSS   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
embedding files into templates
 
Post new topic   Reply to topic    BlogHarbor Community Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
cr
Guest





PostPosted: Mon Nov 22, 2004 4:43 pm    Post subject: embedding files into templates Reply with quote

I have recently experimented with embedding an include file tag into the base of the category/article templates and it was successful. I followed the directions from the bottom of the file manager page that shows how to include files into the blog, and i placed that code in the article template at the bottom and it worked great! Very Happy

My question is this. I would like to have that file change depending on which category the visitor is in. So for instance if the category was:

Sports > Baseball > SF Giants

Is there a way that I can tell it to bring up a file based on the category, 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
...you get the point.

Or maybe you know of a smarter way to do this. So that if giants.txt was a roster of all the players, then it could be dynamically added to every giants page where I post articles. And it would change based on the team. How would you recommend doing this? I have .txt files ready to upload with all of this content I would like to be specific per category. Thanks!
Back to top
cr
Guest





PostPosted: Mon Nov 22, 2004 9:35 pm    Post subject: working with ifelse statements Reply with quote

I have been working on a few ideas, am I anywhere close with these ideas?
From a Perl script it would seem to do it like this:

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"}

or perhaps like this:

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"; }

but when I try to work with blogharbor i am trying to tweak it out. Maybe something like this, although the code still seems wrong:

{{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}}

So any ideas on how to work this would be great Very Happy
I am pretty new to coding in general, but I have plenty of time on my hands to learn. Thanks for all the help!
Back to top
john
Site Admin


Joined: 16 Mar 2004
Posts: 3434

PostPosted: Tue Nov 23, 2004 1:37 am    Post subject: Re: embedding files into templates Reply with quote

Here is an example of what you are looking for:

Code:
{{if category.label eq "Secure"}}
  We are in the Secure Category
{{elsif category.label eq "Main Page"}}
  We are on the Main Page
{{else}}
  We are lost, Toto!
{{/if}}


You can include files uploaded into the File Manager like this:

Code:
{{if category.label eq "Secure"}}
  {{include name="templates/secure.txt"}}
{{elsif category.label eq "Main Page"}}
  {{include name="templates/mainpage.txt"}}
{{else}}
  {{include name="templates/other.txt"}}
{{/if}}


Hope this helps.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cr
Guest





PostPosted: Tue Nov 23, 2004 1:50 pm    Post subject: Job well done! Reply with quote

EXACTLY what I was looking for!

A+ for getting back to me right away. I was redesigning my entire blog this morning and this makes the world of difference. Thank You very much. Blogharbor just got more referrals Very Happy
Back to top
cr
Guest





PostPosted: Wed Nov 24, 2004 3:04 pm    Post subject: one last question...maybe :) Reply with quote

I was just thinking, what happens if you have 2 categories named the same thing. For example:

Sports > Baseball > San Francisco > Giants

and...

Sports > Football > New York > Giants

If I had a file called "giants.txt" that got included if the category was "giants" then this would cause a problem because of the 2 different text files needed. So what code would I need to call the .txt file from the whole category breadcrumb?

{{if category.label eq "New York/Giants"}}
{{include name="newyork/giants.txt"}}

I know this probably won't work but it must be something similar right?Thanks!
Back to top
john
Site Admin


Joined: 16 Mar 2004
Posts: 3434

PostPosted: Wed Nov 24, 2004 11:08 pm    Post subject: Re: one last question...maybe :) Reply with quote

Good question, but there is not really a great answer for this... The macros we are talking about here were designed more for displaying data than testing the values of data, so there really is not an elegant way to determine which Giants category you are in.

That being said, you could test against the {{category.rss_url}} value instead of the {{category.label}} value, as this variable would be different for each category...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cr
Guest





PostPosted: Sat Nov 27, 2004 1:06 am    Post subject: Thanks! Reply with quote

John,

Thanks for the rss_url tip. It worked out perfectly. That handled several issues for me and I am very thankful for your support and quick responses. I am becoming very, very satisfied with blogharbor! Expect some referrals and a long term customer!

The rss_url tip you gave me is a great way to get around the "main page" issue for now until that is changed in the future. By offering an alternative everytime it grabs the main page rss url, I was able to customize specific content for the main page and search results pages, while at the same time, using dynamic category based results for the rest of the blog.
Back to top
tigersi



Joined: 20 Apr 2005
Posts: 174

PostPosted: Fri Oct 07, 2005 3:45 pm    Post subject: clarifying with components Reply with quote

Hi John,

Want to make sure I understand what this code is doing so see if it can help me.

In this post, http://forums.blogharbor.com/viewtopic.php?t=1593, I asked for ways to create code in the article template to randomize ads based on categories. You indicated the article template won't have the flexibility but I could do the process described in this thread as an alternative.

Can I use the idea here in components? That is, that I could write conditional code into the component so that different ads will be diplayed within a component based on the category?
_________________
Thanks!
Kathy (aka, Roaring Tiger)
http://bigcatchronicles.blogharbor.com
Back to top
View user's profile Send private message Visit poster's website
john
Site Admin


Joined: 16 Mar 2004
Posts: 3434

PostPosted: Fri Oct 07, 2005 3:50 pm    Post subject: Re: clarifying with components Reply with quote

Can I use the idea here in components? That is, that I could write conditional code into the component so that different ads will be diplayed within a component based on the category?

Yes, the code described here will also function as part of a component.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Search all BlogHarbor support resources.
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    BlogHarbor Community Forum Index -> Tips and Tricks All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum