PHPLover
PHPLover

Reputation: 13005

How to access value from URL in smarty template?

I'm newbie in smarty so facing so much difficulties in using it. I've got the following URL :

http://localhost/schooling_needs/sneeds1.0/web/control/modules/chapter_youtube_videos/chapter_youtube_videos.php?chapter_id=102

I want to assign the value of chapter_id to a text field in smarty template. For that I wrote following code, but it's not getting the correct value.

<input type="text" name="chapter_id" id="chapter_id" value="{$chapter_id}">

The text field is not getting any value. Would you please help me by telling how should I assign the value of chapter_id to the above textfield? Thanks in Advance.

Upvotes: 3

Views: 15039

Answers (2)

Jon
Jon

Reputation: 4736

You need to assign it within your code to the smarty template you are using. For example:

$smarty->assign('chapter_id', $_GET['chapter_id']);

before you fetch/display your template. ^^

Due to OP's limitations, using the built-in smarty instead of assigning to page individually.:

{$smarty.get.chapter_id}

would provide it directly from the $_GET array.

Upvotes: 6

Alexxus
Alexxus

Reputation: 992

You can access the $_GET parameters in your template by using $smarty.get.parametername. So your code should look like this:

<input type="text" name="chapter_id" id="chapter_id" value="{$smarty.get.chapter_id}">

You can read more in the Smarty documentation

Upvotes: 0

Related Questions