expressionegine matrix plugin check if field is empty - matrix

I have a matrix field with several columns. When user submits the form I want to display only column fields user entered.
How can I check if matrix field is empty?
Just to clarify I'm talking about expressionengine's Matrix extension.
For example this wont work for me since the row can be submitted empty:
{if "{exercise_set1:total_rows}" >= 1}
{exercise_set1:table cellspacing="0" cellpadding="0" class="format_head"}
{/if}

To check if there are any rows filled use
{if your_matrixfield:total_rows>0}
{your_matrixfield}
Do your thing
{/your_matrixfield}
{/if}
I had the problem that users could attachs files to an entry but when no files were attached do not generate the Gallery

You just want to check to see if anything is set?
{matrix_tagpair}
{if column_var}{column_var}{/if}
OR
{if column_var != ""}{column_var}{/if}
{/matrix_tagpair}

Related

Find locator with contains text (Robotframework)

From this code as below:
<span id="cTDQo7-img" class="z-menu-img"></span> payment
<span id="cTDQo7-img" class="z-menu-img"></span>
"payment"
I would like to get locator use keyword contains but the word "payment" is
a lot of the page such as payment1,payment2,payment3
And id is not unique.
I tried to use the code below but not work for me.
//a[contains(.,'payment')]
//span[#class='z-menu-img'] [contains(.,'payment')]
//span[#class='z-menu-img'] and [contains(.,'payment')]
//span[#class='z-menu-img'] contains(.,'payment')
Option 1 : Use the other attributes in combination with text
//a[#class='z-menu-cnt z-menu-cnt-img' and normalize-space(.)='payment']
Option 2: Specify the position if you have multiple elements without unique attributes/path
(//a[contains(.,'payment')])[1]
The second xpath will identify the first occurrence of the link contains text 'payment'. You can change the tagname and index based on your interest.

ASP-Classic Get information from dynamic field

I have an old ASP-page that contains a form but for some reason, a part of the code doens't work anymore.
The code was working before because I write the content of the form in a database and there I have values from the past.
A short description of my page:
I have a [select multiple]-field and when you select one (or more) option I create another input field (for every selected option a new fied). The ID of this field is FSRow_ + an edited value of de selected option (no spaces, commas, ...).
When I submit the form I want to read the content of my new fields so I can write this information to my database.
An example:
Suppose I have two selected options, to make it easy: "OptionA" and "OptionB", then I create two new fields (from the source code):
<input name="FSRow_OptionA" id="FSRow_OptionA" type="text">
<input name="FSRow_OptionB" id="FSRow_OptionB" type="text">
When I submit my form, I have this code:
if request.form()
...
getSelectedValues = split(request("OptionList"), ",")
for each li in getSelectedValues
li = replace(li, "'", "''")
li = replace(li, "||", ",")
fsrow = trim(request("FSRow_" & replace(replace(replace(replace(replace(trim(li), " ", ""), "&", ""), "+", ""), ",", ""), "|", "")))
if fsrow <> "" then
[write to DB with dynamic field]
else
[only write selected item]
end if
next
When I look in my database. I have only the information of the selected items (so, my i'm going in my else-code). Not the content of my dynamic field. So I suppose the variable "fsrow" is always empty, even if my new field contains some text.
My questions:
How can I get the content of my dynamic input field?
Any idea what could be wrong because it was working in july 2017 and didn't change anything.
[Not needed anymore, found the solution] I've tried to set an alert or write to the console to debug but this isn't working. How can I debug when I'm in my "for each"-loop?
Edit/Update 1:
As commented by Ricardo Pontual I can use "Response.End" in combination with "Response.Write" before.
If I do this:
Response.Write(li)
Response.Write("## FSRow_" & li & " ## ")
Response.Write("->" & request("FSRow_" & li))
I get this result:
OptionA## FSRow_OptionA ## ->
But in my form/input field I wrote "test" in the field with id "FSRow_OptionA"...
Edit/Update 2:
With a non-dynamic input field I can perfectly read and write the value in my database.
So it's realy a problem with the dynamic field...
Found the problem. This was very old code, from years ago that wasn't written by me, and the problem was the position of < form> and < /form>
Old code (NOT WORKING)
<table>
<form>
<tr>
...
</tr>
</form>
</table>
Changed the code by this:
<form>
<table>
<tr>
...
</tr>
</table>
</form>
I changed the order of < table> and < form> and it works now!

Xpath get element above

suppose I have this structure:
<div class="a" attribute="foo">
<div class="b">
<span>Text Example</span>
</div>
</div>
In xpath, I would like to retrieve the value of the attribute "attribute" given I have the text inside: Text Example
If I use this xpath:
.//*[#class='a']//*[text()='Text Example']
It returns the element span, but I need the div.a, because I need to get the value of the attribute through Selenium WebDriver
Hey there are lot of ways by which you can figure it out.
So lets say Text Example is given, you can identify it using this text:-
//span[text()='Text Example']/../.. --> If you know its 2 level up
OR
//span[text()='Text Example']/ancestor::div[#class='a'] --> If you don't know how many level up this `div` is
Above 2 xpaths can be used if you only want to identify the element using Text Example, if you don't want to iterate through this text. There are simple ways to identify it directly:-
//div[#class='a']
From your question itself you have mentioned the answer for it
but I need the div.a,
try this
driver.findElement(By.cssSelector("div.a")).getAttribute("attribute");
use cssSelector for best result.
or else try the following xpath
//div[contains(#class, 'a')]
If you want attribute of div.a with it's descendant span which contains text something, try as below :-
driver.findElement(By.xpath("//div[#class = 'a' and descendant::span[text() = 'Text Example']]")).getAttribute("attribute");
Hope it helps..:)

[Smarty, and maybe doctrine]

I'hv got a problem when I am using foreach in smarty,
an array with 2 item was loop in a foreach, but the result is it loop 3 time.
I use doctrine to get a list of review by a user from database
Doctrine_Core::getTable('review')->findByUser($userId);
then I assign it to smarty and loop in foreach:
{foreach from=$reviewList item=review}
<p>User {$review.User.name} said: {$review.content}</p>
{/foreach}
However the result is e.g.:
User Joe said: yoyo
User Mary said: hihi
User said:
Please notice that the extra row doesn't get anything from the array.
I have checked that there is only 2 record in database, and I have count the $reviewList by count($reviewList), the result is also 2.
When I insert one more record to database, the forloop also loop extra one time.
Can anyone tell me why this happen? Thanks a lot!
This should filter the empty line:
{foreach from=$reviewList item=review}{if $review.User.name}
<p>User {$review.User.name} said: {$review.content}</p>
{/if}{/foreach}

Smarty change elements in array

I have an array in my template files ($data) witch looks like this
$data.1.name
$data.1.date
$data.1.place
$data.2.name
$data.2.date
$data.2.place
$data.3.name
$data.3.date
$data.3.place
now I would like to check the entire array and remove an item where the date is older then today.
The date check i figured out but i'm stuck at removing the item.
So let's say item 2 is older, the result should look like
$data.1.name
$data.1.date
$data.1.place
$data.3.name
$data.3.date
$data.3.place
Anyone an idea how i do this? If it is at all possible?
{foreach from=$data item=val}
{if $val.date >= $smarty.now}
{$val.name}
{$val.date}
{$val.place}
{/if}
{/foreach}

Resources