Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Display variables from a template function
Old 08-26-2011, 01:53 PM Display variables from a template function
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Hi,

I have having a problem understanding how to display values of variables in PHP from using templates.

Below is the code for the template function and the template i am trying to call (with variables included). Templates are saved as HTML files iwth variables in them.

As you can see below, i've tried including the normal call to a session $_SESSION... and in a PHP statement {$_SESSION...

What is displayed on the page is exactly as below.

I have also tried to record these onto normal variables too, ie:
Code:
$userName = $_SESSION['userName'];
Thanks.

Code:
function gettemplate($template,$endung="html") {
    $templatefolder = "templates/default/";
    return str_replace("\"","\\\"",implode("",file($templatefolder."/".$template.".".$endung)));
}
Code:
echo gettemplate("headerInfo");
Code:
<p class='smallRight'>Welcome back, $_SESSION['userName'].You last logged in on {$_SESSION['lastLogin']}</p>
<p class='smallRight'><a href='index.php?act=logout' title='Logout'>Logout</a></p>

Last edited by feraira; 08-26-2011 at 01:56 PM..
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2011, 09:24 PM Re: Display variables from a template function
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
So are you trying to parse PHP from a loaded .txt document? If so, I'm not sure that would work, as it's not generally a good way to do it. You might want to take a look at PHP's eval() function, although it's dangerous if you're handling user input with it. Make sure to thoroughly sanitize your input, even if it's yours, before passing it through eval().
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-27-2011, 07:01 AM Re: Display variables from a template function
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
They're not text documents, they're HTML documents.

For example, I have a HTML document tha details the section on a page where it displays the users login details ie. Welcome back X, you last logged in on xx.xx.xxx

If I want to use this information on every page then it means copying and pasting the code into every page.. Then if I want to change it for any reason ie. Welcome back X. You're last login was on xx.xx.xxxx

By using a template all i need to do is call the template and edit the template if i want.

Does that make sense?

Thank
feraira is offline
Reply With Quote
View Public Profile
 
Old 08-27-2011, 07:14 AM Re: Display variables from a template function
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
http://www.webresourcesdepot.com/19-...plate-engines/
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 08-27-2011, 10:15 AM Re: Display variables from a template function
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Why are you not using standard include()??
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-28-2011, 02:54 AM Re: Display variables from a template function
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
Quote:
Originally Posted by mgraphic View Post
Why are you not using standard include()??
And, of course, a php file, that allows you to have variables
(
you can also execute html files, by adding into .htaccess the
AddType application/x-httpd-php .html .htm
)
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 08-28-2011, 11:48 AM Re: Display variables from a template function
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Quote:
Originally Posted by mgraphic View Post
Why are you not using standard include()??
I am using the include function to include my functions file.

All i want to be able to do is in a certain area on a page that i'm building, be able to insert a snippet (one line) of code and be able to display what i need ie. that of a login form box, login details, content area etc...
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Display variables from a template function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34844 seconds with 12 queries