Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-12-13 06:35:38
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Dynamic Text
I’m stumped! I have a weather station that generates data and uploads in to my site every 15 minutes or so. I can upload it in just about what ever format I wish – .txt, converted to .htm, etc.
What I’m trying to do – mainly out of curiosity – it to figure out how I can integrate dynamic text into TextPattern…. How can I create an article, say “Current Weather Conditions” and have that article pull in data from this text file when viewed?
I also upload dynamic graphic files every 15 minutes and solving that riddle was a snap since I could call the image file from inside the article. Help!
Offline
#2 2006-12-13 06:59:37
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Dynamic Text
See: Txp PHP tag and PHP include().
Offline
#3 2006-12-13 14:04:43
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
Mary – Thank you, you are my new hero! :) I performed a simple test and, at first, had some problems until I realized Textile was interferring with it. I was able to have Textpattern pull in a simple .txt file with no problems and think I can eventually work it a finished product.
My only glitch is that I have lost my formatting (font type, size and color) because the text isn’t going through Textile. Is there a way around this?
I also lost my linebreaks. So a file that is suppose to looks like this:
12/13/2006 4:37:11 AM
No thunderstorms detected
NexStorm V1.30.0.2171:LD250
Now looks like this:
12/13/2006 4:37:11 AM No thunderstorms detected NexStorm V1.30.0.2171:LD250
Last edited by Grimalkin (2006-12-13 14:48:27)
Offline
#4 2006-12-13 15:58:03
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Dynamic Text
If you are doing a straight include, where the include already has the markup you want, then you can leave Textile on for your article, and just make use of escaping. Like this:
notextile. <txp:php>include('the-file.php');</txp:php>
Offline
#5 2006-12-13 17:09:24
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
Great, I just tried it and I’m a little better off. What I’m playing with at the moment is weather warnings. My weather software writes the file as a straight up .txt file and I just used this, per your wonderful instructions, to display the data within the file:
<txp:php>include('/home/shappee/www/www/private/weather_data/1.txt');</txp:php>I flipped Textile back on for the article but the text still is displayed in a different font/size/color then my “normal” articles. Does this make sense? It isn’t preserving the look and feel of the rest of the site. I’m still new to CSS and PHP so I’m probably not explaining it in the best possible manner.
Are you saying that I need to include font information in the 1.txt file itself?
Thanks again!
Update: I think I might be getting my arms around this. I looked at the CSS stylesheet and am hunting down the variable for the font info for the articles….
Last edited by Grimalkin (2006-12-13 17:21:46)
Offline
#6 2006-12-13 17:31:22
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
Success! I solved the font issue. Any idea on my one other issue (at the moment): The missing line breaks?
Thank again, Mary, for all your help!
Offline
Re: Dynamic Text
you could try using bc.
instead of notextile.
It will wrap it in <pre><code>
… preserving your spacing and linespacing etc. You will need to change how pre and code are displayed in your CSS.
If it at first won’t work, try bc..
(with two dots) and for the item after it where a normal paragraph should begin again, begin the line with p. my text...
(that marks where the blockcode (bc) should stop.
Actually, maybe even a multi-line notextile..
(two dots) might work.
TXP Builders – finely-crafted code, design and txp
Offline
#8 2006-12-14 02:23:08
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Dynamic Text
You don’t want to use bc
, you just need notextile.
As for “missing line-breaks”, I’d have to see the include file. My guess is that you have just linefeeds and no markup, which you need for it to display right in (X)HTML.
Offline
#9 2006-12-14 21:49:37
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
Mary, is there a way I can e-mail you the file in question? :)
The file is just a plain ol’ standard notepad’ish .txt file that is generated whenever a lightning storm is in the area. It doesn’t contain any additional formatting instructions.
On a lark I manually opened up the file and added a couple of <br> and </br> tags at the end of each line and it worked great. One of my problems is that this file is automatically created every 60 seconds and loaded to the server. I can’t configure the software to add those tags….
Last edited by Grimalkin (2006-12-15 00:59:02)
Offline
#10 2006-12-15 13:41:01
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Dynamic Text
Okay, what you’ll need to do is something like:
<txp:php>
// where the file is
$file = '/home/shappee/www/www/private/weather_data/1.txt';
// grab the file contents into a variable
$weather = file_get_contents($file);
// parse the contents how you want
// You can even have them parsed by Textile, if you wanted.
// this just converts those newlines into actual br tags
$weather = nl2br($weather);
// display the contents
echo $weather;
</txp:php>
It would be better to parse the file before-hand, when it is created, but if you can’t, this is the next best thing.
Offline
#11 2006-12-15 19:43:31
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
Mary – you are a total goddess! :) It works great! Thank you so very much!
Offline
#12 2006-12-18 06:34:52
- Grimalkin
- New Member
- Registered: 2006-12-13
- Posts: 7
Re: Dynamic Text
OK, one last question. <hopefully> :)
I have another text file that has the data in about four columns. When I suck it in I lost that formatting. Is there any tricks I can use to perserve spacing? Thank you!
Offline