I have two web-parts on a same page template and I would like to hide one one of them using a value coming through my query string parameter.
How can I hide a web-part using a query string parameter in Kentico 8 and above?
I am assuming you know how to reach visibility section of the webpart.
Click on the little arrow icon highlighted.
Let's assume the querystring parameter name is cat and you want to show it if it's value is "Visible"
So you can do it like this
{% if( QueryString.GetValue("cat") = "Visible" {true}else{false} #%}
You can also do it in a reverse way like this
**{% if( QueryString.GetValue("cat") != "Visible" {false}else{true} #%}**
Edit:-
You can use this to check multiple values for a single clause like this
if( QueryString.GetValue("cat") != "Visible" && QueryString.GetValue("cat") != "")
You can also use this to combine multiple queries like I did in my case.
if( QueryString.GetValue("cat") != "" || QueryString.GetValue("Author") != "" || QueryString.GetValue("tagname") != "") {true}else{false} #%}
Of course, you can interchangeably use "||" and "&" by tweaking your logic.
I hope this is enough to handle to all your cases. Let me know if it works.
Related
I have a grid in .net mvc core that I apply a search in every column in the grid based on a search string. It works on every search string I put in EXCEPT for date strings like yyyy-mm-dd ( ie when hyphens are used).
When I put in yyyy or mm or dd individually the search works. But when I put in yyyy plus the hyphen (ie yyyy-) , it never finds any records.
Here is my c# code for the filter:
if (!String.IsNullOrEmpty(searchString))
{
serviceRequests = serviceRequests.Where(s => s.Id.ToString().ToLower().Contains(searchString.ToLower())
|| s.DateTimeSubmitted != null && s.DateTimeSubmitted.ToString().ToLower().Contains(searchString.ToLower())
|| s.RequestHeading != null && s.RequestHeading.ToLower().Contains(searchString.ToLower())
|| s.RequestDescription != null && s.RequestDescription.ToLower().Contains(searchString.ToLower())
|| s.RequestorId != null && s.RequestorId.ToLower().Contains(searchString.ToLower())
|| s.RequestorFirstName != null && s.RequestorFirstName.ToLower().Contains(searchString.ToLower())
|| s.RequestorLastName != null && s.RequestorLastName.ToLower().Contains(searchString.ToLower())
);
}
How does the filter syntax have to be changed to allow for "yyyy-mm-dd" strings to be used? Why does the hyphen cause problems?
Thanks
It looks like DateTimeSubmitted is of type DateTime. What happens if you use the DateTime.ToString() method? Citing from the documentation:
Converts the value of the current DateTime object to its equivalent
string representation using the formatting conventions of the current
culture.
So, the string representation may not what you expect, e.g. 01.01.0001 00:00:00
I suggest to format the source with a format string like this:
DateTimeSubmitted.ToString("yyyy-MM-dd");
Or another format that fits your needs.
turns out it was a slight twist on suggestion:
|| s.DateTimeSubmitted != null && s.DateTimeSubmitted.Value.ToString("yyyy-MM-dd").ToLower().Contains(searchString.ToLower())
Had to change DateTimeSubmitted.ToString to DateTimeSubmitted.Value.ToString(yyyy-MM-dd) to be able to specify formatting. - ie adding .value before .ToString
Thanks so much!
I have a problem in report studio. please help me to figure this out..
i have a optional prompt, i want to check whether the value is selected or not..
Please help how to check..
if (?parameter? is null ) then ('1') else ('2')
or
if (ParamDisplayValue('parameter') is null ) then ('1') else ('2')
Both the above are not working..
Suppose if i select any value in the prompt then the else part works and i get the result as 2, if i wont select anything then i'm not getting the result as 1
My guess, without doing extensive testing, is that an empty optional prompt doesn't exist at all and can't be compared to null. That said, I believe there's an easy fix.
Since you know that when you select an item '?parameter? is null' will return false, '?parameter? is not null' should return true and you can reverse the logic:
if (?parameter? is not null) then ('2') else ('1')
Try to put a conditional block. Set a block variable of type boolean with this expression:
ParamDisplayValue('myParam') is null
Then go to your conditional block again switch property "current block" to yes/no.
When yes (meaning that our block variable is true so the parameter is null) add a text item and just write "All".
When no add a text item with source type as report expression and write ParamDisplayValue('myParam')
P.S: there is also a way to count how many values the user selected (so as not to display all of them 1 by 1 but just show "62 values selected") but it needs some javascript and a hidden prompt field.
Use ParamCount
More details here:
http://joesanswers.blogspot.com.au/2008/09/checking-for-empty-parameters-in-cognos.html
How to set the option (of select) to selected to match the current language of the page? Is there a way to inline it and simplify it something like this:
(value="en" #{Locale}==='en' ? ',selected="selected"': '')
I have tried some answers on this site, but they do not seem to work. Thank you.
This is the view:
if(#{Locale} ==='en')
option(value="en", selected="selected") #{English}
option(value="bg") #{Bulgarian}
else if(#{Locale} === 'bg')
option(value="en") #{English}
option(value="bg",selected="selected") #{Bulgarian}
Adapted from this answer, you could create a mix-in that handles the logic for you:
mixin lang-option(code, name)
if (Locale === code)
option(value=code, selected="selected")= name
else
option(value=code)= name
+lang-option('en', English)
+lang-option('bg', Bulgarian)
This solution works if you need to parameterize the 'disabled' attribute as well. Jade will not output attributes that evaluate to false.
//Selects the option when option.value == selectValue
mixin selectOption(option, selectValue)
option(value=option.value, disabled=option.disabled, selected=(option.value==selectValue))= option.label
I have a scenario in which there are three fields, based on the selection of First Field( 3 values in first field),the next field is getting values ( it is a dialogue list field) through DBcolumn. and then on the basis of selection of second field the third field is coming. All the above mentioned field are dialogue list field.
The issue is with multi selection, when ever multi values are selected out of first field the next fields are coming as DBColumn is used (due ot lesser values), but Since second filed has lots of values, we have to use DB Look up and here the multi selection is not fetching the data for corresponding filed.
Eg. I have a field named Database (having 3 values), and other two fields are Project(many values) and Brand.
I am using DBColumn to get Values in Project Field from Database field Selection (multi-selection), which I am getting properly (using #if), but after multi selection of Project Field (there are many values) I am not able to get values in next field (using DBLookup).
Please let me know any workaround....
First: Your code would have probably helped in solving this problem, although I think, it is not code- related:
Please check the field- property "refresh fields on keyword change" on the Project and the property "Refresh Choices on document refresh" on the Brand- Field.
If you do not get ANY- values whenever you select a second Project, then check, if your Key for Lookup is correctly used as an Multiple value for your DBLookup and that it does not try to lookup something like "value1;value2" instead of "value1" : "value2"...
Bets practice for debugging something like this, is to have a "BrandList" field, Computed for Display, hidden, with the DBLookup in it:
_viw := "YourViewName";
_crit := Project;
_col := 2;
REM "Don't do lookups, if project is empty";
#if( _crit = "" ; #Return( "" ) ; "" );
_lkp := #DBLookup( "" : "NoCache" ; _viw ; _crit ; _col );
#if( #IsError( _lkp ) ; "" ; _lkp );
And the let the brand point to this field (simply use the fieldname as Formula). that way you can easily debug the returned values.
In addition: If you are not sure, that there will be Brands for every Project you select, you need to add [FailSilent] to the lookup, otherwise the whole lookup will fail, if only one of the projects cannot be found... _lkp := #DBLookup( "" : "NoCache" ; _viw ; _crit ; _col; [Failsilent] );
BUT: Failsilent is very bad when debugging something, as you never get an error Message...
AND: For debugging purposes, you of course do NOT use the #IsError- line and simply return _lkp...
I want to test if a CKEditor ( Rich Text ) field is empty as part of some business logic.
I do not want to use the built in validation features.
If a CK Editor field has previously had text and then this text is deleted there is still content e.g.
<p dir="ltr">
</p>
I can get a handle to this text string using :
dataVar = xspdoc.getDocument().getMIMEEntity(dataNamevar).getContentAsText();
Is there a way to test if the CKEditor field is empty of visible text ?
Technically speaking, if it has what amounts to a a single visible newline in it as you've shown in your question, it isn't really "empty".
Realistically, you'll have to parse the content value to find out if there is content that is not either inside tags or the few special characters like and so on.
I tend to do this in js, if I have to, by taking the whole string of text and splitting it into an array based on "<" then taking each element of the array and removing an text to the left of an ">", then trim. That leaves me an array of either empty strings or text that is outside any tags. From there it's easy enough check for any of strings in the array to see if they are not empty, and not " ".
This may be more cumbersome then some built in parser that I don't know, but it's fairly reliable and quick. (and a very similar method can be used in formula language as well).
In ssjs formula you could:
var checkString = #trim(#replacesubstring(#implode( #trim (#right( #explode( sourceHTMLstring , "<" ) , ">" ) ) , " "), " " , ""));
if(checkstring == "") {
// *** You have no content
} else {
// *** you have content
}
Obviously this could be done just as easily in pure javascript, but the old formula language is so ingrained in my head, I'd go this way just out of habit.
** Also note: You may want to check for an <img> tag in there somewhere in case someone has done absolutely nothing other than put an image in the rich text.
CKEditor has its own API, I guess this is the right method to use:
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
This might be helpful: http://xpagetips.blogspot.com/2011/10/be-careful-with-empty-ckeditor-rich.html
Check if CKEditor is empty
For any browser
var editor=CKEDITOR.instances.editorName.getData();
I found best answer for this
function validateCKEDITORforBlank(ckData)
{
ckData = ckData.replace(/<[^>]*>|\s/g, '');
var vArray = new Array();
vArray = ckData.split(" ");
var vFlag = 0;
for(var i=0;i<vArray.length;i++)
{
if(vArray[i] == '' || vArray[i] == "")
{
continue;
}
else
{
vFlag = 1;
break;
}
}
if(vFlag == 0)
{
return true;
}
else
{
return false;
}
}
Link