DEV Community

dgloriaweb
dgloriaweb

Posted on • Edited on

1

Use session and cookie variables in Smarty Php template

Cookies: if they are in devtools/Application tab, we can access like this:
Chrome Devtools: Name: companyId Value: 8
Smarty: {$smarty.cookies.companyId}

Session variables:
Set: $_SESSION["userid"] = 1
{$smarty.session.userid}

Parameters in url: example: myurl.com?myindex=34
{$smarty.get.myindex}

Get contents of an array, $_SESSION for example:
{$smarty.session|@json_encode}

To see which file is running the current page:
{$smarty.server.SCRIPT_NAME}

Top comments (1)

Collapse
 
andersbjorkland profile image
Anders Björkland

Good job hammering away with Smarty! I hope it works well enough for your project. Just giving it a glance over, I think it would take me a while getting used to it.

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Explore this practical breakdown on DEV’s open platform, where developers from every background come together to push boundaries. No matter your experience, your viewpoint enriches the conversation.

Dropping a simple “thank you” or question in the comments goes a long way in supporting authors—your feedback helps ideas evolve.

At DEV, shared discovery drives progress and builds lasting bonds. If this post resonated, a quick nod of appreciation can make all the difference.

Okay