Super globals and constants in twig

Even supper globals like _POST, _GET and CONSTANTs should be rendered as variables from controller to twig and they are not directly accessible in twig?

Show us your code.

I did not yet code it. I just ask super globals and constants are not directly accessible in twig code? Please let me know.

Hello nimasdj,
Try this:

{# $_POST #}
{{ app.request.parameter.get("page") }}  

{# $_GET #}
{{ app.request.query.get("page") }} 


  • Nicolas

How about constants? I do use language constants. Plz advice

Try this:

{{ constant('Namespace\\Classname::CONSTANT_NAME') }}

Sorry I don’t understand why namespace and class? Language files contain just simple constants. Please clarify.

Do you speak about Twig Constants or PHP Constants?

I mean php constants. How to access them in twig templates?
I am not familiar with twig constants. What are them?

Here is an example who explains what I have written above:



My language files just contain simple php constants, not a class. How to access this kind of php constants that are not class constants?

Can you show me 2/3 lines of this file?

define(“CONFIRMED”, “Confirmed”);
define(“CANCELLED”, “Cancelled”);
How to access them?

any advice yet about constants?
also in tp of my controller I added:

$_SESSION['username'] = 'blah';

then in twig

{{ app.session.get('username') }}

but this is blak. what should I do?

{{ app.request.session.get("username") }}

Thanks but I am still waiting your kind help about constants.

I do not really understand why you manage Languages by this way.
I have to see more code to help you.

In my old code I had a language.php file that just define constants e.g.
define(“CONFIRMED”, “Confirmed”);
when I want to show a page first I require that language.php file to get defined constants then in my template I had:
Status: <?=CONFIRMED?>
This way I could change the language without editing template rather than hard-coding in template like:
Status: Cofirmed.
Now how to get this php constants in twig? please advice.

In top of controller I added:
$_SESSION[‘username’] = ‘blah’;
and from symphony profiler toolbar I ass “Has Session: Yes”
But I don’t get the session variable with:
{{ app.request.session.get(“username”) }}
plase advice.

I invite you to use the Symfony2 Session Interface (HttpFoundation Component)

Have a glance to : Link