• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Get all variables assigned to Smarty – Part 1

Get all variables assigned to Smarty – Part 1

I’ve been working with the PHP templating engine Smarty at a new job and needed to be able to dump a list of variables that had been assigned to Smarty for debugging purposes. This quick post shows how to dump the variables in your PHP code.

get_template_vars()

Smarty’s get_template_vars() function returns the variables assigned using the assign() function as an associative array where the array key is the name of the variable and the array value is the variable value.

You can also get the values assigned from the config using get_config_vars() and the usage is exactly the same as illustrated here.

Assuming $smarty is a Smarty instance, use the following code to dump the assigned variables using the print_r() function:

print_r( $smarty->get_template_vars() );

The data could instead be returned into a variable and something else done with it:

$variables = $smarty->get_template_vars();

Part 2

I have written a follow up to this post which gives a couple more examples and shows how to return just one variable assigned to Smarty instead of everything.

Check Out These Related posts:

  1. Get unique array values with PHP
  2. Intialise an array in PHP with default values
  3. Bash For Loop
  4. var_dump or print_r inside a Smarty template

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap