Condition depending other field - plone

i have 2 fields (fieldA and fieldB)
what i want :
- if the fieldA contains something then the fieldB should not be displayed
what i try :
<span tal:replace="here/getFieldA" />
<span tal:omit-tag="here/getFieldA" tal:replace="here/getFieldB" />
so it doesn't work
thanks for your help

What you are looking for is tal:condition, possibly combined with the not: and exists: prefixes:
<span tal:replace="here/getFieldA" />
<span tal:condition="not:exists:here/getFieldA" tal:replace="here/getFieldB" />
Alternatively, you can use the | operator, which acts like an if operator, testing existence of the first element. If it doesn't exist, it'll use the next expression, and so on:
<span tal:replace="here/getFieldA | here/getFieldB" />
The tal:omit-tag attribute means something very different. If it's expression evaluates to True, then the tag, and only the tag itself, is omitted from the output. This is best illustrated with an example:
<span tal:omit-tag="">
<i>This part will be retained</i>
</span>
Rendering that piece of pagetemplate results in:
<i>This part will be retained</i>
The surrounding <span> tag was omitted, but the contents were preserved.

Try
<span tal:condition="here/getFieldA" tal:replace="here/getFieldB" />
The Zope Page Templates Reference http://docs.zope.org/zope2/zope2book/AppendixC.html

This is a refinement of the original answer, based on the comments:
<tal:block
tal:define="zone here/getZoneintervention;
thezone python:', '.join(zone);
dep here/getDepartements;
thedep python:', '.join(dep)">
<span tal:condition="zone" tal:replace="thezone" />
<span tal:condition="not:zone" tal:replace="thedep" />
</tal:block>

Related

thymeleaf how to get an input backing bean generated name attribute

Is it possible with thymeleaf to retrieve an input "generated" name attribute ?
I need to create a div with an id equals to an input name attribute.
Input names are generated via the th:field.
Markup:
<input type="radio" id="winterTiresInstalled" th:field="*{winterTiresInstalled.value}" />
Generated markup:
<input id="fld_winterTires" type="radio" name="vehicle.winterTiresInstalled.value" />
What I want :
<div th:id="???" />
to obtain :
<div id="vehicle.winterTiresInstalled.value" />
So, how can I retrieve the generated name attribute value "vehicle.winterTiresInstalled.value" with thymleaf ?
I could do it in js but I would prefer doing it in my template.
Thank you.
David
th-attr is best suited for this use case.
<a href="#" th:attr="data-id=${object.getId()}, data-name=${object.getName()}"/>
The above will result is something like this(haven't tested)
<a href="#" data-id="420" data-name="user-link"/>
Did the solution in javascript for now. I change the id of div after the page loads.
I would prefer do it directly in my template but can't figure out a way to do it with thymeleaf.

Rich Snippets Nesting Issue

I've never used Rich Snippets before, so this is a little bit of a learning curve for me. I believe my issue is a nesting problem but I can't find any documentation anywhere that explicitly states how to nest these properties correctly.
I'm wanting to index a single-product review with multiple reviews into Rich Snippets with classic ASP pulling in different data feilds, here is my code:
<div>
<div itemscope itemtype="http://data-vocabulary.org/Review">
<span itemprop="itemreviewed">Forma Stanzol</span><br />
By <span itemprop="reviewer"><%=formaStanzolReviewArray(0,i)%></span><br />
<time itemprop="dtreviewed" datetime="<%=FormatDateTime(formaStanzolReviewArray(1,i),2)%>"><%=FormatDateTime(formaStanzolReviewArray(1,i),2)%></time> <br />
<span itemprop="description"><%=formaStanzolComment%></span>
</div>
</div>
This returns the Error: No rich snippet will be generated for this data, because it appears to include multiple reviews of an item, but no aggregate review information.
So, I added a dummy Aggregate code with static values, here's what it looks like all together:
<div>
<div itemscope itemtype="http://data-vocabulary.org/Review">
<span itemprop="itemreviewed">Forma Stanzol</span><br />
By <span itemprop="reviewer"><%=formaStanzolReviewArray(0,i)%></span><br />
<time itemprop="dtreviewed" datetime="<%=FormatDateTime(formaStanzolReviewArray(1,i),2)%>"><%=FormatDateTime(formaStanzolReviewArray(1,i),2)%></time> <br />
<span itemprop="description"><%=formaStanzolComment%></span>
</div>
<div itemscope itemtype="http://data-vocabulary.org/Review-aggregate">
<span itemprop="itemreviewed">Forma Stanzol</span>
<span itemprop="rating" itemscope itemtype="http://data-vocabulary.org/Rating">
<span itemprop="average">9</span>
out of <span itemprop="best">10</span>
</span>
based on<span itemprop="count">5</span> user reviews.
</div>
</div>
This causes my "Reviews" to not error but then all of my "Aggregate Reviews" push out this Error: No rich snippet will be generated for this data, because it appears to include multiple aggregate reviews of many items, instead of a single aggregate review of one item.
Seems like it's working against itself no matter what I do, so that's why I believe this to be a nesting issue.
How can I fix this?
EDIT: Ideally, I don't event want the Aggregate view of this item. The reviewer, item name, review date, and review description is all I need.
EDIT EDIT: This code is also running in a For loop where its getting information from the database with each pass.
Ok so the issue here was that a website, with a single product, but multiple reviews needs only one "Review-Aggregate" and one "Rating" itemtype. However, multiple "Review" itemtypes must be used.
So, my For Loop creates a "Review" for each row in the database, using the related data feilds and then after the conditional statement, the "Review-Aggregate" and Rating" codes are placed.
Code:
For i = 0 to uBound(formaStanzolReviewArray,2)
reviewCount = reviewCount + 1
formaStanzolComment = trim(formaStanzolReviewArray(2,i))
'Do not show reviews with empty comments
If Not (formaStanzolComment = "") OR isNull(formaStanzolComment) Then
%>
<div>
<div itemscope itemtype="http://data-vocabulary.org/Review">
<span style="position: absolute; left: 9999px;" itemprop="itemreviewed">Forma Stanzol</span>
Rating: <span itemprop="rating"><%=formaStanzolReviewArray(3,i)%></span> -
By <span itemprop="reviewer"><%=formaStanzolReviewArray(0,i)%></span> -
<time itemprop="dtreviewed" datetime="<%=FormatDateTime(formaStanzolReviewArray(1,i),2)%>"><%=FormatDateTime(formaStanzolReviewArray(1,i),2)%></time> <br />
<span itemprop="description"><%=formaStanzolComment%></span>
</div>
</div>
<%
sumRating = sumRating + formaStanzolReviewArray(3,i)
End If
Next
ratingAvg = sumRating / reviewCount
%>
<div style="position: absolute; left: 9999px;">
<div itemscope itemtype="http://data-vocabulary.org/Review-aggregate">
<span itemprop="rating" itemscope itemtype="http://data-vocabulary.org/Rating">
<span itemprop="worst">1</span>
<span itemprop="average"><%=ratingAvg%></span>
out of <span itemprop="best">5</span>
</span>
based on <span itemprop="votes"><%=reviewCount%></span> ratings.
<span itemprop="count"><%=reviewCount%></span> user reviews.
</div>
</div>
<%
Think of it as multiple User reviews in the For Loop, but we collect all of those reviews once in the aggregate, and then give that aggregate a rating scale.
Hope this helps anyone having nesting issues.
Please Note: I am using classic ASP for this particular code.

How to get the sqrt symbol in a buttons value?

im trying to get the sqrt symbol to display inside my button. I cant seem to get it to work. Here is my button code
<input type="button" id="sqrt" value="sqrt" onclick="insert function here">
We the value, i need to get the sqrt symbol to show up and I cant seem to figure out how.
If you need to find a specific symbol you can refer to W3's Character Entity Reference Chart.
The Square Root (√) symbol can be displayed using one of the following:
√
&Sqrt;
√
√
For example:
<input type="button" value="√" /> <!-- or... -->
<input type="button" value="&Sqrt;" /> <!-- or... -->
<input type="button" value="√" /> <!-- or... -->
<input type="button" value="√" />
Personally I'd opt for either √ or √ as these directly reference the symbol's Unicode ID. A browser may not necessarily have any mapping defined for √ or &Sqrt;.
JSFiddle demo.
Use √:
<input class="sqrt-input" type="submit" value="√" />
Change the font if you don't like the default look:
/* If find Verdana pretty good for this and it's available
on almost every browser. */
.sqrt-input {
font-family: Verdana;
}
The simplest way is to use the character itself:
<input type="button" id="sqrt" value="√" onclick="...">
You then need to make sure that the character encoding is utf-8 and this is declared in HTTP headers, but you should do that anyway.
Use an img tag inside a button tag like this :-
<button TYPE="submit" >
<img src="" >
</button>
Here put the path of your image in the src attribute. You can also add hieght and width properties to define size for your button and attributes like align="absmiddle" to position image in middle of the button.
for example
<button TYPE="submit" >
<img style="height:25px;width:65px;" src="http://2.bp.blogspot.com/_0agwm6I7YZE/TO_DccbrDBI/AAAAAAAAMEU/0OADo56Xqxw/s1600/square-root.jpg" align="absmiddle" >
</button>

How to get the title attribute of a input element? - webdriver

How to get the attribute of Title in the input element
<input type="image" title="Previous Page">
<input type="image" title="First Page">
<input type="image" title="Next Page">
<input type="image" title="Last Page">
What have you tried? Typically something like the following should work:
WebElement element = driver.findElement(By.tagName("input"));
String title = element.getAttribute("title");
The answer provided by Jim Evans is the correct one imo, but for a more specific one i'd advise something like below. Remeber that copy-pasta might not work and you need to change something to be able to work on your full HTML.
List<WebElement> elements = driver.findElements(By.tagName("input"));
for (WebElement element : elements) {
if (element.getAttribute("type").equals("image")) {
System.out.println(element.getAttribute("title"));
}
}
The above code will loop for all the in your webpage that are from type="image" and print on the console the "title" attribute of each one of those.
Still thing you should vote Jim's answer as the correct one though.
First, you need to identify the input element from which you want to get the value of the attribute title .
Then something like the following must work.
element.getAttribute("title");
Its very simple and work for as well.
String title = driver.getTitle();

Styling Wicket datetimefield

I am using the DateTimeField component of Wicket, but I am struggling to apply any styling to it. The HTML snippet is this:
<span id="creationDate" wicket:id="creationDate" />
and the accompanying Java is:
add(new DateTimeField("creationDate", new PropertyModel<Date>(this, "creationDate")));
Which works, but produces this (which I have tidied up):
<span id="creationDate" wicket:id="creationDate">
<wicket:panel xmlns:wicket="http://wicket.apache.org">
<span style="white-space: nowrap;">
<input type="text" wicket:id="date" size="12" value="28/11/11" name="creationDate:date" id="date1f"/>
<span class="yui-skin-sam">
<span style="display:none;position:absolute;z-index: 99999;" id="date1fDp"></span>
<img style="cursor: pointer; border: none;" id="date1fIcon" src="wicket/resource/org.apache.wicket.extensions.yui.calendar.DatePicker/icon1-ver-1322148000242.gif" alt="" title=""/>
</span>
<input type="text" wicket:id="hours" size="2" value="14" name="creationDate:hours"/>
<span wicket:id="hoursSeparator"> :</span>
<input type="text" wicket:id="minutes" size="2" value="17" name="creationDate:minutes"/>
</span>
What I am hoping to do is get the components separately, then either add style or class attributes to them. Any way this can be done?
You can use the method public Component add(final Behavior... behaviors) defined in the super class Component.
What you are looking for is the behavior AttributeAppender with which you can add CSS id/classes or every other attribute you want to append.
See the API: http://wicket.apache.org/apidocs/1.5/org/apache/wicket/behavior/AttributeAppender.html
UPDATE
I just got a quick look at the source code of the DateTimeField. Unfortunately, you can't access the components separately.
I can think of two ways how you can style the components:
You can put the whole DateTimeField inside a custom div and then, for example, accessing the textfields via cascading css selectors. (e.g. #myDiv input)
or you create your own DateTimeField class with the existing source code and put your css id/classes there.
Turns out you can just override the HTML, in this case by replacing DateTimeField.html in the org.apache.wicket.extensions.yui.calendar package. This then replaces the default HTML, and is where I added the class details.

Resources