{if $GLOBALS.current_user.group.id != "Employer"}
<li><a href="{$GLOBALS.site_url}/find_jobs/" >[[Find Jobs]]</a></li>
<li class="sep"></li>
<li><a href="{$GLOBALS.site_url}/add_listing/?listing_type_id=Resume" >[[Post Resumes]]</a></li>
<li class="sep"></li>
{/if}
Just trying to figure out this code. I think it is saying "If the current user IS? or ISN'T? a member or the group 'employer' put the following links in..."
Which is it?
Thanks
!= means is not equal to, the exclamation point (!) is a negation operator:
$a = 5;
if ($a == 5) {
// executed if condition is true
}
if ($a != 5) {
// executed if condition is not true
}
!= means "not equals", so "If the current user ISN'T an employer..."
"isn't" (because of the !=)
I suppose this is in some sort of templating language? That isn't what normal PHP looks like. In any case, the != definitely means IS NOT, so it means if the current user IS NOT an employer, insert the links.
!=
not equal
thus if they are not group.id employer then put in the list items and anchor tags
If the id is not equal to "Employer", then condition is satisfied, process inner block which appears to be adding <li>'s to the page
Weird code. But it means Show this html elements if group of current user IS NOT Employer.
Related
EDIT: Due to the general syntax of AlpineJS, writing a ternary operator inside curly brackets is a mistake you may easily run into.
This is just a "grammar" issue but I really want to figure it out... Let's jump into it.
Everything is ok if I write:
:class="{ 'some_class': activeSlide == slide }"
On the contrary it doesn't work (i.e. 'some_class' is not added as a class) if I write:
:class="{ activeSlide == slide ? 'some_class' : '' }"
What's wrong with it?
(I don't think it's relevant, but you can have a look at the entire code here, inside 'template' tags: link)
The ternary operator works only with the non-object class syntax:
:class="activeSlide == slide ? 'some_class' : ''"
You can use the shorthand conditionals as well:
:class="activeSlide == slide && 'some_class'"
I have a page with products/items. Some with options that the user needs to choose and some with no options at all.
In my shopping cart page, I display this ordered items/products with the options user chose if needed. This is how I iterate over products/item and the options
{#each eachitem as item }
<li>
Here it is : {item.item.id} -- {item.price} -- {item.qty}
{#if item.item.checkedoptions.checkoptions === 0 }
<p> Display NO OPTIONS</p>
{:else}
{#each item.item.checkedoptions.checkoptions[1] as opti}
<li style="list-style-type : none">
Options : {opti.optionname} - {opti.optionvalue}
</li>
{/each}
{/if}
</li>
{/each}
The issue is when there are no options, I get the error in my dev tools that reads "Cannot read property 'length' of undefined", of course because item.item.checkedoptions.checkoptions[1] is empty. I tried to use length but couldn't figure out how to attach it to item.item.checkedoptions.checkoptions do I put it inside () or [] or what?
How do you write if statement that if item.... length === 0 {do something}?
If I can't get the length, how do I solve this problem, do I do something in the script before I iterate?
How do you solve this issue?
In your if statement you are not actually checking the length of checkoptions you are comparing it directly with 0
You should change this to #if item.item.checkedoptons.checkoptions.length === 0
There is a HTML like this.
<div class="paginate_box">
<span class="disabled prev_page">Back</span>
<span class="current">1</span>
<a rel="next" href="page2">2</a>
<a rel="next" href="page3">3</a>
<a class="next_page" rel="next" href="page2">Next</a>
</div>
To get biggest number of the pages I wrote this.
doc = Nokogiri::HTML(html)
doc.xpath('//div[#class="paginate_box"]/a[not(#class="next_page")]').last.text
#=> "3"
At first I wrote a[#class!="next_page"] instead of a[not(#class="next_page")], but it didn't match the tag. Why it doesn't match? What am I doing wrong?
So the problem here is you are trying to use != on an attribute (#class) that is only present on the last node. This means #class cannot be compared on the other nodes because it is essentially saying nothing != 'next_page'.
Since nothing is not comparable to anything, operators (including != and =) will always return false.
In your not function you are asking if nothing = 'next_page' which is always false (as explained above) and thus not makes it true and the element is selected.
You can prove this by adding a class to one of the other anchor tags and then use the != version.
Side note you can simplify the code to just use xpath
doc.xpath('//div[#class="paginate_box"]/a[not(#class="next_page")][last()]').text
#=> "3"
# Or
doc.xpath('//div[#class="paginate_box"]/a[not(#class="next_page")][last()]/text()').to_s
#=> "3"
Also if next_page anchor is always present and always last and the highest page number always precedes it then you can avoid the condition altogether:
doc.xpath('//div[#class="paginate_box"]/a[position()=last()-1]').text
#=> "3"
Here we are saying find the anchor in the position right before the last one in that div.
Alternative:
doc.xpath('//div[#class="paginate_box"]/a[last()]/preceding-sibling::a[1]').text
#=> "3"
This will find the last anchor then all the anchor siblings preceding it in bottom up order and we are selecting the first one in that list.
My company uses ways to hide most data on their website and i'm tying to create a driver that will scan closed jobs to populate an array to create new jobs thus requiring no user input / database access for users.
I did research and it seems this can't be done the way i'm doing it:
# Scan page and place 4 different Users into an array
String name = [nil, nil, nil, nil]
String compare_name = nil
c = 0
tr = 1
while c < 4
String compare_name = driver.find_element(:xpath, '//*
[#id="job_list"]/tbody/tr['+tr.to_s+']/td[2]/span[1]/a/span/text()[2]').gets
if compare_name != name[c]
name[c] = compare_name
c = +1
tr = +1
else if compare_name == name[c]
tr = +1
end
end
end
Also i am a newb learning as i go, so this might not be optimal or whatever just how i've learned to do what i want.
Now the website code for the item i want on the screen:
<span ng-if="job.customer.company_name != null &&
job.customer.company_name != ''" class="pointer capitalize ng-scope" data-
toggle="tooltip" data-placement="top" title="" data-original-title="406-962-
5835">
<a href="/#/edit_customer/903519"class="capitalize notranslate">
<span class="ng-binding">Name Stuff<br>
<!-- ngIf: ::job.customer.is_cip_user --
<i ng-if="::job.customer.is_cip_user" class="fa fa-user-circle-o ng-scope">
::before == $0
</i>
> Diago Stein</span>
</a>
</span>
Xpath can find the Diago Stein area, but because of it being a text object it doesn't work. Now to note something all the class titles, button names, etc are all the same with everything else on the page. They always do that which makes it even harder to scan because those same things are likely elsewhere that might not have anything to do with this area of the site.
Is there any way to grab this text without knowing what might be in the text area based on the HTML? Note "Name Stuff" is the name of a company i hid it with this generic one for privacy.
Thanks for any ideas or suggestions and help.
EDIT: Clarification, i will NOT know the name of the company or the user name (in this case Diago Stein) the entire purpose of this part of the code is to populate an array with the customers name from this table on the closed page.
You can back your XPath up one level to
//*[#id="job_list"]/tbody/tr[' + tr.to_s + ']/td[2]/span[1]/a/span
then grab the innerText. The SPAN is
<span class="ng-binding">Name Stuff<br>
<!-- ngIf: ::job.customer.is_cip_user --
<i ng-if="::job.customer.is_cip_user" class="fa fa-user-circle-o ng-scope">
::before == $0
</i>
> Diago Stein</span>
The problem is that this HTML has some conditionals in it which makes it hard to read, hard to figure out what's actually there. If we strip out the conditional, we are left with
<span class="ng-binding">Name Stuff<br>Diago Stein</span>
If we take the innerText of this, we get
Name Stuff
Diago Stein
What this does is you can split the string by a carriage return and part 0 is the 'Name Stuff' and part 1 is 'Diago Stein'. So you use your locator to find the SPAN, get innerText, split it by a carriage return, and then take the second part and you have your desired string.
This code isn't tested but it should be something like
name = driver.find_element(:xpath => "//*[#id="job_list"]/tbody/tr[' + tr.to_s + ']/td[2]/span[1]/a/span").get_text.split("\n")[1]
all im trying to do is to use the simple continue tag but it keeps giving me error like this:
string(145) "Smarty error: [in module_db_tpl:onlyimage4;image_detail line 26]: syntax error: unrecognized tag 'continue' (Smarty_Compiler.class.php, line 590)"
my code is as follow:
{foreach from=$itemlist item="item"}
< .. SOME CODE ..>
{if $maxCol == $colm}
</div>
{assign var ='colm' value = 0}
{$row++}
{continue} **<- THIS IS THE PROBLEM**
{/if}
<.. SOME CODE ..>
{/foreach}
does anyone have any idea whats wrong, I've been googling and see no comments of such sort everyone seem to suggest that this should work.. any ideas guys...
Old question, but you need to use: {$continue} (including the $)
For smarty 2:
I don't think the tag exists. if you read this thread you can see that there are people that want it, and a suggestion to fix it like so. (have not tried)
compiler.continue.php
<?php
function smarty_compiler_continue($contents, &$smarty)
{
return 'continue;';
}
?>
(Bold part my addition)
Create these two files (in this case just one) and put them into your plugins directory
(notice the naming convention compiler.xxx.php).
The good news is, for smarty 3 there is such a tag! see the manual, with example:
{$data = [1,2,3,4,5]}
{foreach $data as $value}
{if $value == 3}
{* skip this iteration *}
{continue}
{/if}
{$value}
{/foreach}
{*
prints: 1 2 4 5
*}