In Twig, check if a specific key of an array exists
Twig example: {% if array.key is defined %} // do something {% else %} // do something else {% endif %}
Twig example: {% if array.key is defined %} // do something {% else %} // do something else {% endif %}
You can use the define plugin. I use it by doing something as simple as this in your webpack build file where env is the path to a file that exports an object of settings: // Webpack build config plugins: [ new webpack.DefinePlugin({ ENV: require(path.join(__dirname, ‘./path-to-env-files/’, env)) }) ] // Settings file located at `path-to-env-files/dev.js` … Read more
If your DBMS does not impose limitations on which table you select from when you execute an insert, try: INSERT INTO x_table(instance, user, item) SELECT 919191, 123, 456 FROM dual WHERE NOT EXISTS (SELECT * FROM x_table WHERE user = 123 AND item = 456) In this, dual is a table with one row only … Read more
If the first statement returns true, then the entire statement must be true therefore the second part is never executed. For example: $x = 5; true or $x++; echo $x; // 5 false or $x++; echo $x; // 6 Therefore, if your query is unsuccessful, it will evaluate the die() statement and end the script.
private static final boolean enableFast = false; // … if (enableFast) { // This is removed at compile time } Conditionals like that shown above are evaluated at compile time. If instead you use this private static final boolean enableFast = “true”.equals(System.getProperty(“fast”)); Then any conditions dependent on enableFast will be evaluated by the JIT compiler. … Read more
I don’t think there is a way to do variable length string comparisons completely in preprocessor directives. You could perhaps do the following though: #define USER_JACK 1 #define USER_QUEEN 2 #define USER USER_JACK #if USER == USER_JACK #define USER_VS USER_QUEEN #elif USER == USER_QUEEN #define USER_VS USER_JACK #endif Or you could refactor the code a … Read more
VBA does not have a Continue or any other equivalent keyword to immediately jump to the next loop iteration. I would suggest a judicious use of Goto as a workaround, especially if this is just a contrived example and your real code is more complicated: For i = LBound(Schedule, 1) To UBound(Schedule, 1) If (Schedule(i, … Read more
You can assign default parameter values inline when you first create the mixin: @mixin clearfix($width: ‘auto’) { @if $width == ‘auto’ { // if width is not passed, or empty do this } @else { display: inline-block; width: $width; } }
The zmbq solution is good, but cannot be used in all situations, such as inside a block of code like a FOR DO(…) loop. An alternative is to use an indicator variable. Initialize it to be undefined, and then define it only if any one of the OR conditions is true. Then use IF DEFINED … Read more
Python 3.3 and above Python 3.3 introduced contextlib.ExitStack for just this kind of situation. It gives you a “stack”, to which you add context managers as necessary. In your case, you would do this: from contextlib import ExitStack with ExitStack() as stack: if needs_with(): gs = stack.enter_context(get_stuff()) # do nearly the same large block of … Read more