View previous topic :: View next topic |
Author |
Message |
cr Guest
|
Posted: Mon Nov 22, 2004 4:43 pm Post subject: embedding files into templates |
|
|
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!
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
|
Posted: Mon Nov 22, 2004 9:35 pm Post subject: working with ifelse statements |
|
|
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
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
|
Posted: Tue Nov 23, 2004 1:37 am Post subject: Re: embedding files into templates |
|
|
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 |
|
|
cr Guest
|
Posted: Tue Nov 23, 2004 1:50 pm Post subject: Job well done! |
|
|
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 |
|
Back to top |
|
|
cr Guest
|
Posted: Wed Nov 24, 2004 3:04 pm Post subject: one last question...maybe :) |
|
|
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
|
Posted: Wed Nov 24, 2004 11:08 pm Post subject: Re: one last question...maybe :) |
|
|
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 |
|
|
cr Guest
|
Posted: Sat Nov 27, 2004 1:06 am Post subject: Thanks! |
|
|
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
|
Posted: Fri Oct 07, 2005 3:45 pm Post subject: clarifying with components |
|
|
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 |
|
|
john Site Admin
Joined: 16 Mar 2004 Posts: 3434
|
Posted: Fri Oct 07, 2005 3:50 pm Post subject: Re: clarifying with components |
|
|
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 |
|
|
Search all BlogHarbor support resources.
|
View previous topic :: View next topic |
|