I try to hide the getPage [[+pageNav]] Placeholder if there is no pagination. But I can't do the following.
[[!+pageNav:notempty=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]
Does someone know how I can hide the element with an apropriate output filter? (without own extra snippet). I also tried the following and some other (not likely to work variations).
[[!+pageNav:isnot=``:then=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]`
Are you calling that code in a chunk that is cached?
Otherwise i've experienced this aswell and it seems custom placeholders sometimes behave that way, it's probably due to the fact that they actually have some unprocessed value during the IF computation but when it's actually output you see nothing. Or that the value is somehow "null" instead of "" while modx output filter might do a strict comparison.
If you're not calling it in a cached chunk or part of code, i suggest first trying with another getPage placeholder such as pageCount or total.
Like:
[[!+pageCount:gt=`1`:then=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
If that still doesn't work, a last resort in the form of a simple snippet will always solve it, like:
[[!outputPagination? &total=`[[+total]]` &limit=`XX` &output=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
In snippet:
if ($total > $limit) {
return $output;
}
Shouldn't it be...
[[!+page.nav:notempty=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
Well, there is a much more easier way to do it than in the first answer. It's like TheMistaC says, even if my answer is a lot easier:
[[!+page.nav:notempty=`
[[!+page.nav]]
`]]
I use it to display a list of articles with getResources, so I know this works fine.
Related
I am working on Verigy 93K test program and I have a logic that I would like to know if there's an equivalent code in Origen.
I am working on Verigy 93K test program and I have this logic (IF condition) that I need to insert in my flow.
Basically, I have a variable called 'INSERTION' and this will have different values like 'GCORR', 'VCORR' and others.
I would like to know if there's an equivalent code like this in Origen.
I attached a snapshot, hope that it can help clarify my question more.
In this logic, I would like to check the INSERTION value and if the value is not equal to GCORR or VCORR, the logic should pass, else, fail.
Here is the screenshot:
This pull-request adds an official API for this.
This example would be implemented as:
whenever_any ne(:INSERTION, 'GCORR'), ne(:INSERTION, 'VCORR') do
# Your tests in here
end
That would produce something logically equivalent and which can be re-targeted to other platforms.
If you don't care about that and want to produce exactly as you have it in the above example, then this should work too (where the OR is hard-coded for V93K syntax):
whenever ne(:INSERTION, 'GCORR|VCORR') do
# Your tests in here
end
Here is the preliminary documentation of this feature from the above PR - https://github.com/Origen-SDK/origen_testers/blob/66345c9422d9fa6b2577af20110259e45c2bdd26/templates/origen_guides/program/flowapi.md.erb#L71
I couldn't find api support on flow control or variable values beyond "if/unless_enable" support which can help check for 1 or zero. One way is to use render.
render 'if #INSERTION != "GCORR|VCORR" then'
render '{'
# your code for non-GCORR_VCORR flow
render "} \n else \n { \n } "
I'm trying to output a template variable inside the if statement in ModX, but it gives no output.
I have multiple pages with links to articles and the point is to only output template variable content on the first page but not the others.
// This gives no output:
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=``]
// This outputs "yes" on the first page and "no" on others:
[[!#get.page:is=`1`:or:is=``:then=`yes`:else=`no`]]
I've even tried this, but it still does not give any output. I guess the problem is not about the output modifier:
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=`[[*content]]`]
I'm using ModX Revo 2.7.0
Any help is appreciated, thanks in advance!
Actually in your case missing a double closing angle bracket "]]"
[[!#get.page:is=`1`:or:is=``:then=`[[*content]]`:else=``]]
The `or:is=` is matching against an empty state. Unless that is intentional you should be able to remove it. Also, the `:else=`` is the default state, so, you don't need that either.
The following should work and you'll have cleaner code:
[[!#get.page:is=`1`:then=`[[*content]]`]]
Currently the code below will only show the HeroImage if one exists. If one doesn't exist, it doesn't show the other image blogImage. How can I change the code to show blogImage, if there is no HeroImage. Thanks
<img src="[[*HeroImage:isempty:then='[[*blogImage:phpthumbof=`w=1200&h=800`]] [[*]]':else='[[*HeroImage:phpthumbof=`w=1200&h=800`]] [[*]]']]" alt="[[*pagetitle]]" class="img-responsive"/>
Using the :default option should be enough:
[[*HeroImage:default=`[[*blogImage]]`:phpthumbof=`w=1200&h=800`]]
Ifempty and (default, empty, isempty) works like default value if input not specified else it returns the input value itself. So second else statement has no meaning and doesn't work.
For your purpose you can use "is" modifier like
[[*HeroImage:is=``:then=`[[*blogImage:phpthumbof=`w=1200&h=800`]]`:else=`[[*HeroImage:phpthumbof=`w=1200&h=800`]]`]]
And keep in mind using back-ticks for modx templating
I'd roll this a slightly different way, but it's likely the same result:
[[*HeroImage:neq=``:then=`[[*HeroImage:phpthumbof=`w=1200&h=800`]]`:else=`[[*blogImage:phpthumbof=`w=1200&h=800`]]`]]
I like to keep things DRY, that's why I want to have the following in one of my steps:
if first(:css, "#blabla") != nil
find_by_id(blabla).click
end
find_by_id(....)
....
This means, that it will look for a certain element, and if it exists, it will click on it. If not, I will not lose time (my default wait time is 20 secs, which will be used if I put find instead of first there.
The main issue is that I don't want to lose time when checking for a certain element in this case, but I am also wondering if this is a good approach.
I see the issue that your code does unnecessary second query to browser (you already have first(:css, "#blabla") so no need to do find_by_id(blabla))
I propose you to find element using one query:
el = first('#blabla')
el.click unless el.nil?
Note that there is no losing time here as first doesn't block.
However, first doesn't check that there no other elements on the page. You can add :maximum to check it:
el = first('#blabla', maximum: 1)
el.click unless el.nil?
When you're using #find to decide on element presence, you should reduce the wait time for just that call:
if page.has_css?('#blabla', wait: 0)
# Do something
end
However, in your special case, the suggested solution is even better, because it saves you multiple "find" calls for the same element.
I am using watir-webdriver (0.5.3) in a Cucumber (1.1.9) test. I am attempting to verify the text value of an <acronym> tag. The code is legacy, and there are plans to change it to a <div> or <span> tag, but in the mean time I have to deal with it. I first attempted:
#browser.acronym(:id => /expense_code(.*)/).text
I received the following error:
NoMethodError: undefined method `acronym' for #<Watir::Browser:0x33e9940>
I poked around in the Watir code to see how tag objects were being created, and found that they seem to be dynamically created based on the HTML5 spec, but then I also found a comment in element.rb stating that they are no longer being created from the spec. At any rate, I couldn't see an easy way to inherit a <span> object and call it an <acronym> object. So, I looked into alternatives, and found the element object.
#browser.element(:id => /expense_code(.*)/).text
This code works, but it takes about a minute to traverse my page. I'm stuck with the regex for now, as the tag id is actually dynamically generated and I don't currently have a way to figure out those values. This is what the tag actually looks like:
<acronym class="editable select fillwith:exp_codes default:E100"
title="Expense Code: Expenses" id="expense_code114_582_10777">
E100 </acronym>
I would appreciate any thoughts on how I can improve the performance of my test.
Is that class name predictable? could you construct that from a set part plus the text you are about to validate (it's the same in your example above) and go that way?
acronym = 'E100'
browser.element(:class, 'editable select fillwith:exp_codes default:#{acronym}'.text.should == acronym
Does using XPath to limit the elements to just acronym tags help performance?
#browser.element(:xpath, "//acronym[contains(#id, 'expense_code')]")
UPDATE: As Chuck mentioned, CSS-Selector is also an option:
#browser.element(:css => "acronym[id^=expense_code]")
I was recently stealing logic from Watir 1.6.5 to make custom locators/collections for my page objects and I noticed in the Watir::TaggedElementLocator, it kind of supports any method that the element supports. Noticing in Watir-Webdriver that elements have a tag_name() method, I thought I would try the same and it looks like it works.
So you can use tag_name as a locator by doing:
#browser.element(:tag_name => 'acronym', :id => /expense_code(.*)/).text
I'm not sure what order the locators get run in, so since the regex is expensive, it might be faster to get all the acronym elements and then find the one with the right ID:
#browser.elements(:tag_name, 'acronym').find{ |acronym|
acronym.id =~ /expense_code(.*)/
}.text
While I think it makes the code look better, unfortunately I'm not sure if its any faster. I am guessing the performance of each will depend on the specific page layout being tested.
I'm not sure what the proper etiquette is here, but this is the answer I came up with using Chuck's reply and feedback from jarib in the #watir IRC chat. With all my examples, expense_code = 'E100'.
#browser.element(:tag_name => "acronym",
:class => "default:#{expense_code}").text
The above code works at a very reasonable speed and doesn't require an xpath. It is a shortening of the following code:
#browser.element(:tag_name => "acronym",
:class => "editable select fillwith:exp_codes default:#{expense_code}").text
I learned that I didn't need to pass the whole string. Anything in a class delimited by a space is dealt with gracefully by watir. I adapted that code from this xpath:
#browser.element(:xpath => "//acronym[contains(#class,
\'editable select fillwith:exp_codes default:#{expense_code}\')]").text
The gotcha in that code above was needing to escape out the ' around the class values so that it would evaluate correctly.
Just searching for the class (code below) did not work. I have no idea why. I did notice that it pounded the database with requests. Whatever it was doing, the page didn't like it. Though the reason it was trying multiple times is I slipped a wait_until_present in there.
#browser.element(:class, "editable select fillwith:exp_codes
default:#{expense_code}").text
Thanks for the help. :)