Accessing Request Variables from Smarty Templates

Request variables available in PHP scripts can be accessed from your Smarty templates through the reserved template variable {$smarty}. Request variables include $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, and $_SESSION.

Examples:

Output the value of $_GET[‘page’] from the url “http://www.jampmark.com/index.php?page=about

{$smarty.get.page}

Output the value of $_POST[‘page’] from a posted form

{$smarty.post.page}

Output a cookie variable, $_COOKIE[‘status’] from request header

{$smarty.cookies.status}

Output a server variable, $_SERVER[‘SERVER_NAME’]

{$smarty.server.SERVER_NAME}

Output a system environment variable, $_ENV[‘PATH’]

{$smarty.env.PATH}

Output a session variable, $_SESSION[‘id’]

{$smarty.session.id}

Output the value of “username” from merged get/post/cookies/server/env

{$smarty.request.username}

Advertisements

1 Comment

  1. MaSlo said,

    August 10, 2009 at 9:11 am

    Thanks a lot, this is exactly what I need at the moment 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: