How display velocity variable in a CSS Class - liferay

Please How can I display $num as a number in the console using velocity template.
I did:
#foreach ($nav_item in $nav_items)
#set( $num = $velocityCount + 1 )
<li class="$nav_item megamenu-$num-columns-group $num" id="layout_$nav_item.getLayoutId()" $nav_item_attr_selected role="presentation">
but when I run it I didn't get the number in the class but it keeped $num.
Solution Please ?
Picture

Short answer, the right way to implement this solution is just using ${theVar}:
<li class="$nav_item megamenu-${num}-columns-group ${num}"

Related

Kentico v9 transformation and Roles

I have an alert section pulling items with a repeater. My transformation pulls date and copy and displays them in UL tags.
I've been asked to make a change where a specific alert would only be seen by people is a specific group/role.
My thoughts were change the page type form with a check box. On the transformation side i would then need a conditional statement where the check box is true and the user is part of specific Role.
My transformation is currently an ASCX and is as follows:
<li><%# Eval("Alert") %></li>
I imagine it being something like this
<% if ( checked = true && role = XX ) { <li>Eval("Alert")</li> } %>
I just can't figure out the conditional statement.
For Text/XML transformation
{% if(checked == true && CurrentUser.IsInRole("MyRole")) {return "<li>" + Alert + "</li>"} %}
ASCX
<%# If(CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("rolename", CMS.SiteProvider.SiteContext.CurrentSiteName) && Eval("checked") == true, "<li>" + Eval("Alert") + "</li>","") %>
I'd recommend to add some CSS class based on your condition:
<li class="<% if(Eval<bool>("FieldsName") &&
CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("rolename", CMS.SiteProvider.SiteContext.CurrentSiteName);) {"alert"} %>">
....
</li>
Having "alert" class added to your li, you can change visibility, colors or whatever you need for that item.
This approach requires ASPX transformation.
You can use the method CurrentUser.IsInRole(, )
I came up with something like:
<%# (checked && CurrentUser.IsInRole("_everyone_", "corporate") ? Eval("DocumentName") : "empty") %>
David

Ideal way to handle layout changes in a list

So I've stupidly designed a list of recent articles, all is good with the world BUT the first 2 entries html are markedly different then the remainder of entries.
I am yet to turn a line of code so any advice anyone an offer is greatly appreciated.
Simplistically the ul would look like:
<li class="1of2"> /* It's number 1 – give it a class to identify it as special */
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
<li class="1of2"> /* It's number 2 – give it a class to identify it as special */
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
<li> /* It's not number 1 or 2 – ie. every other item, NO class per se */
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
If you imagine a 3 column grid for all entries but the first 2 entries are 1.5 columns each. Bit of a noodle scratch going on here, any thoughts gratefully voted upon.
PS. I will be using Stash if that helps !
Just output the class name based on the value of {count}. I've output the whole opening <li> tag here to keep it simple but you could just output the class attribute or class name itself.
{if count<=2}
<li class="special">
{if:else}
<li>
{/if}
<h1>{title}</h1>
... etc.
</li>
Incidentally, I don't think you can have class names that begin with a number.
Here's how I would do it if you want each of the first 2 to have a unique class name:
<li{if count<=2}class="top{count}"{/if}>
that will output
<li class="top1">...
<li class="top2">...
<li>...
If you want the first 2 items to have the same class:
<li{if count<=2}class="whateveryouwant"{/if}>
which will output
<li class="whateveryouwant">...
<li class="whateveryouwant">...
<li>...
Couldn't you do {if count == "1|2"}class="whatever"{/if} ?
Seems you are asking for two unique classes, one for the first entry and one for the second entry. In that case, this will work:
{if count == 1}
<li class="first">
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
{if:else if count == "2"}
<li class="second">
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
{if:else}
<li>
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
{/if}
Also, class names that start with a number will not validate.
You could do it with simple conditionals as well if there is no "other" class that would then require the if:else part of the conditional:
<li{if count == "1"} class="first"{/if}{if count == "2"} class="second"{/if}">
<h1>{title}</h1>
<p>{short_desc}</p>
</li>
This assumes you don't have any other differences, such as different custom fields in one option versus the other, which MediaGirl's suggestion would handle more elegantly. If the only difference between them is class assignment, this is another alternative.

How I can access elements via a non-standard html property?

I'm try to implement test automation with watir-webdriver. By the way I am a freshman with watir-webdriver, ruby and co.
All our HTML-entities have a unique HTML-property named "wicketpath". It is possible to access the element with "name", "id" a.s.o, but not with the property "wicketpath". So I tried it with XPATH but I have no success.
Can anybody help me with a codesnippet how I can access the element via the propertie "wicketpath"?
Thanks in advance.
R.
You should be able to use xpath.
For example, consider the following HTML
<ul class="ui-autocomplete" role="listbox">
<li class="ui-menu-item" role="menuitem" wicketpath="false">Value 1</li>
<li class="ui-menu-item" role="menuitem" wicketpath="false">Value 2</li>
<li class="ui-menu-item" role="menuitem" wicketpath="true">Value 3</li>
</ul>
The following xpath will give the text of the li that has wicketpath = true:
puts browser.li(:xpath, "//li[#wicketpath='true']").text
#=>Value 3
Update - Alternative solution - Adding To Locators:
If you use a lot of wicketpath, you could add it to the locators.
After you require watir-webdriver, add this:
# This allows using :wicketpath in locators
Watir::HTMLElement.attributes << :wicketpath
# This allows accessing the wicketpath attribute
class Watir::Element
attribute(String, :wicketpath, 'wicketpath')
end
This will let you use 'wicketpath' as a locator:
p browser.li(:wicketpath, 'true').text
#=> "Value 3"
p browser.li(:text, 'Value 3').wicketpath
#=> true
Try this
puts browser.li(:css, ".ui-autocomplete > .ui-menu-item[wicketpath='true']").text
Please Let me know is the above scripting is working or not.

Sparkup Syntax for repeating more than just a single element?

Say I have this:
...
<li class='tab'>7</li>
<li class="tab">8</li>
...
...and I'd like to use Sparkup in my editor to add another say 6 tabs...so I run the sparkup command:
li.tab > a[href=#tab2-$]{$}*6
but it comes out all wrong,
<li class="tab">8</li>
<li class="tab">
1
2
3
...
</li>
My first thought was that my syntax should have been:
(li.tab > a[href=#tab2-$]{$})*6
But that did pretty much the same thing...except this time it didn't insert the second number:
<li class="tab">8</li>
<li class="tab">
$
$
$
...
</li>
Now the range problem (starting at 9 instead of 1) is just a minor annoyance, but what if I want it to repeat the li as well as the a tag?
And yes, before you go off about it, I am indeed aware that I could create all of this stuff just using a simple for loop; but that wasn't part of the question now was it?
You are almost there:
li.tab*6 > a[href=#tab2-$]{$}
You want to create 6 <li> so that's where you should put your multiplier.
No need to be defensive.

how to access cck checkbox value from views .tpl

Subject for advanced views theming:
1) Create CCK integer field "field_checkbox" - Single on/of checkbox
Allowed values
0|No
1|Yes
2) In views row-style .tpl
<?php print $fields['field_checkbox_value']->content ?>
doesn't print any value, why?
Other fields output fine.
Thank you in advance!
Resolved:
In views settings field output must be unformatted.
Output of above function return 1.
Useful for advanced views theming, for example:
<h3 class="title <?php if ($fields['field_checkbox_value']->content) print 'another-class' ?>">
<?php print $fields['title']->content ?>
</h3>

Resources