TWIG: What is the similar instruction to PHP's $$var? - twig

I get an array in view and I only know the name (string) of a variable.
I need to evaluate it.
How can I do?

Twig doesn't have variable variables but you can make a twig extension / filter that would sort that problem and it shouldn't be very difficult.
Here is how to do one, in case you haven't been working with this:
http://symfony.com/doc/current/cookbook/templating/twig_extension.html

Related

How to pass variables to layout from handlebars?

I am using handlbars with express/nodejs, and is possible to pass variables individually to the views, but i dont find a way to pass to general layout. How i can do this ?
What is general layout for you?)
As I know Handlebars is a templates engine.
We have a template, we pass variables to it, we got a string with hardcoded variables inside. Templates don't have common scope or something like this. Template engine just helps you to fill string content easier. (html is a string)
But you can create a scope inside of your code and use the same variables for different templates.

Correct way to override content being displayed?

I want to enable the use of codes inside of content on a Drupal website. For example, when creating a block or a node, i want users to be able to insert code like this:
[[EMAIL]]
Depending on what the current language is, it might display a different value. The tricky part is not retrieving the value I want to replace it with, but figuring out at what point I replace it?
What hook or function would I use, to replace any node content that has the specific code in it, with another value? And the same for a block or any other content that is going to be displayed?
I solved this by creating my own input filter. I copied this example.

Twig tests VS php tests

I have to work with an array of information extracted from a database and I want to display each part of this array according to a criterion, so it is better to make the test in the PHP or in the Twig template?
Depends on a couple of things:
the complexity of the test
The number of places you need to execute this test logic in.
If it's just something like a simple comparison like {{ product.color == 'red' ? 'love' : 'hate' }} then you should most likely put it in the twig template itself. If it is more complex it's best to put it in PHP code to keep it readable and thus separate the layout from the logic.
If you need to do this test in more than a couple of places you should also put it in a PHP object method and use that in all of those places. That way you do not have to change the 'red' color in multiple places if you'd ever want to change it.

Passing values between expression engine templates

Any idea about How can I pass hidden values between 2 expression engine templates?
I don't want to use PHP code, is there any plugin or module?
Thanks
Highly recommend using Session Variables.
On your first page:
{exp:session_variables:set name="talking" value="nonsense"}
On your second page:
{exp:session_variables:get name="talking"}
Then you can always delete it afterwards:
{exp:session_variables:delete name="talking"}
If you want to deal with POST variables and set it on the first page via a form submission, then you can get it easily with Mo' Variables:
{post:talking}
What you may be looking for is an add-on called Stash . I think that would do exactly what you need!

How to Iterate a Resharper Template?

I have a small Resharper Template I have written for Null check of a function Parameter (C#).
Check.IsNotNull($param$, "$param$"); - Suggest Parameter - #1
I can now null check the function paramters one by one. But I want to be able to null check all the paramters at once through a template. Is it Possible in Resharper?. Is there someting like a "$Foreach" using which I can loop through parameter variables and write the code to check them one by one ?. (without writing out the foreach into the code)
I see that the "Alt + Ins" does something similar. (Taking all Properties on the class and making them as parameters of a constructor). So hoping that there's a way out.
Sadly, there isn't a way to do that right now. I created an issue at youtrack.jetbrains.net though: RSRP-263951 Live templates: ability to create templates that write code for each parameter/property/field etc.. Vote there if you want to see this feature in future versions of ReSharper.

Resources