How do you do a switch case syntax using Dwoo template engine.
{if 3 == 5}
never gonna happen
{elseif 3 == 3}
if you don't see this, the world is coming to its end
{else}
this will never happen, unless, as previously mentionned, the world is coming to its end
{/if}
http://wiki.dwoo.org/index.php/If
Related
In a Netsuite saved search I am trying to create a formula that - in part - gives a field value if a textfield does not equal a word - in this case the word is "consol". I tried the below but got an error and am lost on how I can accomplish this.
CASE WHEN {custbody_eym_exhibitor_name} = 'Consol' THEN {custrecord511.custrecord501} WHEN {custrecord169.custrecord173} IS NOT NULL AND {custbody_eym_exhibitor_name} IS NOT 'Consol' THEN {custrecord169.custrecord173} ELSE {custbody90} END
Any help is appreciated.
I know Suite Answer Id 10101 suggest you'd be able to do CASE WHEN -- THEN -- WHEN -- THEN -- ELSE -- END. However, this has never worked for me in a saved search. I've always have to do CASE WHEN -- THEN -- ELSE (CASE WHEN -- THEN -- ELSE -- END) END.
If you are trying to do the following:
If custbody_eym_exhibitor_name is Consol then return custrecord511.custrecord501, and stop evaluating.
If custbody_eym_exhibitor_name is not Consol then check if custrecord169.custrecord173 is NULL, and continue evaluating.
If custrecord169.custrecord173 is NULL then return custbody90, and stop evaluating. If custrecord169.custrecord173 is not NULL then return custrecord169.custrecord173, and stop evaluating.
This should work:
CASE WHEN {custbody_eym_exhibitor_name}='Consol' THEN {custrecord511.custrecord501} ELSE NVL({custrecord169.custrecord173},{custbody90}) END
If you wanted to check if custbody_eym_exhibitor_name contains Consol change {custbody_eym_exhibitor_name}='Consol' to {custbody_eym_exhibitor_name} LIKE '%Consol%' .
Also both tests for 'Consol' will be case sensitive. To work around this you can change {custbody_eym_exhibitor_name}='Consol' to LOWER({custbody_eym_exhibitor_name})='consol'
Greetings python experts. I had written an if condition as follows that fails to be false for objects that should be false. I am writing in python 3.8.5. Note instance_list in this example contains a list of resources that are in various states. I only want to append vm_instance_list with resources that are not in a TERMINATED or TERMINATING state.
instance_results = compute_client.list_instances(
compartment_id = compartment_id).data
vm_instance_list = []
for instance in instance_results:
if instance.lifecycle_state != "TERMINATED" or instance.lifecycle_state != "TERMINATING:
vm_instance_list.append(instance)
The above code appends vm_instance_list with every object in the list instance_results, aka each condition is interpreted as True for objects that are in a TERMINATED or TERMINATING lifecycle state. I have had to re-write to nest the if conditions, which works.
for instance in instance_results:
if instance.lifecycle_state != "TERMINATED:
if instance.lifecycle_state != "TERMINATING":
vm_instance_list.append(instance)
I have no idea what why I have had to nest the above if statements and would appreciate if anyone could share some insights.
Thanks so much,
Hank
In your first version, the result is ALWAYS true, so every item is appended.
Your second version is only true if both tests are true.
If you want the first version to behave like the second version, you need an 'and' statement, not an 'or'.
Let's trace through your first if statement in the case when instance.lifecycle_state is equal to "TERMINATED". The condition is as follows:
instance.lifecycle_state != "TERMINATED" or instance.lifecycle_state != "TERMINATING"
We can see that the first part of this statement is false (since lifecycle_state DOES equal "TERMINATED". The second part is true because lifecycle_state indeed does NOT equal "TERMINATING". So this whole expression simplifies to:
False or True
which finally simplifies (by the rules of or) to be just: True. So now we have seen why the body of the if is executed in the first case.
If we do a similar process in your second code snippet, we will see that the first condition is False (since lifecycle_state DOES equal "TERMINATED". So in this case the second condition is not checked, and the body of the if does not execute.
In fact, the second snippet is equivalent to the following condition:
instance.lifecycle_state != "TERMINATED" and instance.lifecycle_state != "TERMINATING"
Note that this is very similar to your original snippet, however we've replaced or with and. In fact, two nested if statements like this are equivalent to a single condition where both parts are joined by and.
By DeMorgan's Laws, this condition is also equivalent to:
not (instance.lifecycle_state == "TERMINATED" or instance.lifecycle_state == "TERMINATING")
which you may find clearer to understand.
I have an object with multiple properties viz propA, propB propC and propD. I want to write a condition with OR checking more than one parameter like below.
{#if cond="'{obj.propA}'.length > 0
|| '{obj.propB}'.length > 0 || '{obj.propC}'.length> 0}
...
{/if}
Now since #if is deprecated in dust, how do i write an equivalent of this with eq or select. Or is there a new helper i can utilize for such scenarios.
I'm assuming that the props you're testing are strings.
This example requires dustjs-helpers >= 1.6.
You can use the {#any} and {#none} helpers mentioned by #rragan like this:
{#select}
{#ne key=obj.propA value="" /}
{#ne key=obj.propB value="" /}
{#ne key=obj.propC value="" /}
{#any}At least one of the above tests was true. At least one prop is not an empty string.{/any}
{#none}None of the tests above passed. All the props are empty{/none}
{/select}
select was recently extended with #any and #none that let you do multiple OR logic. Note that the .length only works because the deprecated #if uses eval. Dust tests use existence/non-existence so I think you can avoid using .length.
If you still prefer #if, see https://github.com/rragan/dust-motes/tree/master/src/helpers/control/if for an interpretive version of it that does not use eval.
select(id="xxx", name="xxxyyy")
- for(var i = 1;i<10;i++){
option(value="#{i}") Some value for #{i}
- }
but it generates the following HTML
<select id="xxxx" name "xxxyyy"></select>
<option value="1">Some value for 1</option>
....
I've tried to include the select inside the for loop and it works as expected (it generates 10 select drop controls with one item on each one of them).
What am I missing here?
I think you've got your indentation messed up. Jade is like coffeescript, in that indentation is significant and donates nesting. See here. So that the Jade engine knows that your option loop should be within the select tag, the option loop needs to be indented from the select statement, whereas you've got yours level with the select statement.
select(id="xxx", name="xxxyyy")
-for(var i = 1;i<10;i++){
option(value="#{i}") Some value for #{i}
-}
I am trying to display conditional text in a Pyramid Chameleon template. Basically, checking if the dictionary key 'maxed_out_alerts' is empty (false) or has a string 'yes' in it.
<p tal:condition="not:maxed_out_alerts"><h3>Maxed Out.</h3></p>
<p tal:condition="maxed_out_alerts"><h3>Not Maxed Out</h3></p>
When 'maxed_out_alerts' is an empty string, 'Maxed Out' is only displayed (correctly). However, If 'maxed_out_alerts' contains 'yes' string both 'Maxed Out' and "Not Maxed Out' are displayed (incorrectly).
It seems that the NOT is always evaluated to a true condition. It should display one or the other messages not both. What am I doing wrong? thanks
For TAL conditionals in python you can say python: and then use a python syntax conditional
<p tal:condition="python:len(maxed_out_alerts) > 0"><h3>Maxed Out.</h3></p>
It could help if you save boolean state in a boolean variable. By storing this information in a string you run into such problems you are facing right now. That's what builtin python types are made for - use them.
As a pyramid developer I would advice to move the logic to evaluate the current value of maxed_out_alerts into a string into a view method and pass the computed string in a dictionary to the renderer/template. This way you can even create tests for the view logic - any pyramid tutorial, simple or advanced shows you how to do that.
A good start for any simple logic - imagine logic gets more complicated or you even have to translate the text for the template.
#view_config(name="yourname", renderer='templates/yourtemplate.pt')
def myview(request):
"""
#get boolean state from model
#could be that you want to have it the other way round
#or do it by using python ternary operator - a if test else b
if model['maxed_out_alerts'] == True:
maxed_out_alerts = 'Maxed Out'
else:
maxed_out_alerts = 'Not Maxed Out'
return dict(maxed_out_alerts = maxed_out_alerts)
In your Template
<h3 tal:content="maxed_out_alerts">text for maxed out alerts</h3>
or
<h3>${maxed_out_alerts}</h3>