Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 04:42 am EDT

Geeklog Forums

Why PHP only in some templates?


Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
What's so special about files like (featured)storytext.thtml and footer.thtml that stops me from directly using PHP in them (like I can in, say, header.php)?

If I try, it's just as if I tried to use PHP code in a regular HTML page.

Yes, of course I can do it via system/lib-story.php, lib-common.thtml, etc. but those files are customized anyway so it's annoying to customize in 2 different places each time instead of one.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I also noticed I can't use PHP towards the end of header.thtml but only towards the end! What's going on?
 Quote

blah

Anonymous
The header.thtml is the only file that you should be able to use php in. The reason for this is they are template files, if it were all php it would cause a ton of overhead and using templates would be meaningless in the first place.

No idea why you can't use php at the end of your header.thtml file other then to suspect you have a typo in your code.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Look, the word php and the code are just shown as HTML. It only happens if the code is around the comment "START OF CONTENT AREA".

And I still like to know how come it just (generally) works in header.thtml. What's so special about it?
 Quote

Status: offline

ajohnson

Forum User
Junior
Registered: 06/16/06
Posts: 26
The reason you are having trouble can be due to two things. One, you are putting the added markup in the wrong place, or two, you are writing invalid markup. There is nothing special about any .thtml file. They are just segments of a web page to be assembled by GL.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Look, if you don't know the answer don't reply, but stop blaming me for not knowing PHP.

It's real simple. PHP works in most of header.thtml, just not if I use it towards the end of the file. In the other templates I've mentioned it doesn't work anywhere.
 Quote

Status: offline

ajohnson

Forum User
Junior
Registered: 06/16/06
Posts: 26
You misunderstand. You need to write valid HTML for a site to render properly. The .thtml pages are segments of a whole page. Just putting a code snippet somewhere , anywhere does not work. You need to place things in such a way that when the pages are joined, the markup is not broken. Yopu are somehow breaking the page. I also know how to write valid html and I make mistakes too. We all do.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Listen, any php code works in header.thtml...unless it's towards the end of the file.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by LWC: And I still like to know how come it just (generally) works in header.thtml. What's so special about it?

Because it's run through eval() and because it's documented that it only works in header.thtml.

bye, Dirk
 Quote

Status: offline

ajohnson

Forum User
Junior
Registered: 06/16/06
Posts: 26
Meh. My bad. I thought LWC was talking about {varname} in the markup. Learn something new every day. Leaves me speechless
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, at least now I know it's documented. What do the other templates use if not eval()? And how come it doesn't work towards the end of header.thtml? Can you at least tell me the percise point when it stops working?

Thanks!
 Quote

blah

Anonymous
Quote by LWC: Look, if you don't know the answer don't reply, but stop blaming me for not knowing PHP.


Sorry for trying to help it wont happen again.
 Quote

blah

Anonymous
btw this bit of code works everywhere in my header.thtml file, including within the comment you seem to be having issues with.

Text Formatted Code

<?php
echo  'blah';
?>

 


I was never trying to suggest you don't know how to code php just that perhaps you had a typo somewhere or something. Not trying to help here but are you sure you incased you code in
Text Formatted Code
<?php and ?>
 
tags?
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Look, any code I write works...unless I put it around said comment. If it's in the beginning of the file, it works. If it's in the middle of the file, it works. If it's in the end of the file, it doesn't work.
 Quote

All times are EDT. The time is now 04:42 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content