I need to make if statement in html template.
Working:
{% if field == 'var_1' or field == 'var_2' %}
but i can't compare rendered variable with None or ' '
{% if field == 'var_1' or field == 'var_2' and 'var_3' != '' %}
last statement is not working.
var_3 in mysql is NULL or contains varchar(200)
What is proper solution to handle this?
You may looking for the isnull() function.
This function returns True if passed a value set to NULL
.....AND NOT IsNull(var3) AND....
Related
I'm fairly new to macros and variables in dbt so apologize if this is really straightforward but I'm attempting the below but it's not recognizing the {{customer_dataset}}.{{table_name}} part
{%- set table_name = 'orders' -%}
{%- set customer_dataset = customer.id -%}
{%- set columns = adapter.get_columns_in_relation(`{{customer_dataset}}.{{table_name}}`) -%}
How do I do this properly if I want to dynamically loop through a bunch of tables for the get_columns_in_relation function?
First off, don't nest your curlies.
Second, get_columns_in_relation expects a Relation, not a string. A Relation is the thing returned by {{ ref() }} or {{ source() }}, so it's easiest to get a Relation from a model name, not a database identifier. If you want to use a table in your database that isn't a dbt model, create a source for it first.
In short, your code should probably look like this:
{%- set columns = adapter.get_columns_in_relation(source(customer_dataset, table_name)) -%}
I want to assign the variable that's exists and not undefined like how the short-circuit evaluation is done in Javascript
<label for="dummy-xyz">{{ data.dummy.id || dummy.id }}</label>
I'm unable to do it with the || operator however
I would like to test whether a python datetime object agrees with today within the browser, using jinja2
Something like
{% if current_user.last_seen_datetime.date() == TODAY %}
how would I get TODAY?
I found the simples solution is to add a function to the User class
def show_paper_suggestions(self):
if self.last_seen_datetime is None:
return 1
else:
return (datetime.datetime.utcnow() - self.last_seen_datetime).days
((DT_STR,20,1252)OccuranceRegion == "US" && ((DT_STR,20,1252)LegalEntity == "AECB" || (DT_STR,20,1252)LegalEntity == "FSB" || (DT_STR,20,1252)LegalEntity == "Both"))
? DATEADD("day",30,CapCreationDt) : (ISNULL(MaxofRevSCIAndSCI) ? (DT_DATE)"1900-01-01" : MaxofRevSCIAndSCI)
Whenever I put conditions as
OccuranceRegion == "US" AND
LegalEntity is null
The result is coming as NULL, I have also checked the value for MaxofRevSCIAndSCI, its not null. Why, it is not going in else part?
Any function of NULL (except the specialised, "NULL-killing" functions ISNULL and the like) evaluates to NULL. You only compare LegalEntity to string constants. These expressions will evaluate to NULL if LegalEntity is NULL. You need to replace the NULL values in LegalEntity with something else. Probably a derived column upstream
ISNULL(LegalEntity) ? "##NULL#' : LegalEntity
would be easier than doing this in the expression itself (because SSIS expressions are hideous to debug).
In my TYPO3 Fluid template I have a value where I would like to check if its not empty before showing it.
My way now:
<f:if condition="{myvalue}">
<div class="myclass">{myvalue}</div>
</f:if>
This works when I type in the backend a value like "test" or "2", and if I dont type anything it won't show the div tag.
But when I type in the backend "0", the condition is also not true. How can I fix that the integer 0 will be showed, and if its empty (in database NULL) not be showed? (its very common that the value will be 0)
Btw i tried things like:
<f:if condition="{myvalue} !=NULL">
<f:if condition="{myvalue} >= 0">
But then also the empty value's wil be show. If I do
<f:debug>{myvalue}</f:debug>
I get things like:
myvalue = NULL
myvalue = 0
myvalue = "test"
So only the first one must not been shown.
I hope someone can help me, thank you.
There are two solutions first is transient field in your model of bool type which getter just checks if value is not null, but additionally returns true if value is 0 (actually in most languages 0 IS a value)
Second solution is even more universal, it's just writing custom ViewHelper, which will allow uou to check if value is 0 or has value:
<?php
namespace VENDOR\YourExt\ViewHelpers;
class notEmptyOrIsZeroViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* #param mixed $value Value to check
*
* #return bool the rendered string
*/
public function render($value) {
return ($value === 0 || $value === '0' || $value) ? true : false;
}
}
So you can later use this as a condition for common <f:if > condition like:
<f:if condition="{yourNameSpace:notEmptyOrIsZero(value: myValue)}">
<f:then>Now it recognizes 0 as a value</f:then>
<f:else>It still DOESN'T recognize 0 as a value</f:else>
</f:if>
I had a similar case, where I wanted to check a fluid variable for 0 or positive integers. A simple >= 0 comparison wouldn't work. In TYPO3 10 LTS I could resolve this problem by doing this:
<f:if condition="{value} === 0 || {value * 1} > 0">
value is zero or positive integer
</f:if>
(Note: this will also allow integer strings, such as "123" or "1st", but not "val3" - basically as you would expect when casting a string as integer in PHP.)
If you just want to check that {value} is not null or empty (but allow zero as a valid value), you can simplify the condition to:
<f:if condition="{value} === 0 || {value}">
value is set and not empty
</f:if>