In data-sly-list I can loop through elements as in following examples
data-sly-list: Repeats the content of the host element for each enumerable property in the provided object.However, what if I want to loop through the first 4 elements or from 8th till 10th elements, how to do so?
Here is a simple loop:
<dl data-sly-list="${currentPage.listChildren}">
<dt>index: ${itemList.index}</dt>
<dd>value: ${item.title}</dd>
</dl>
Use something like this:
<dl data-sly-list="${currentPage.listChildren}">
<div data-sly-test="${itemList.count > 4 && itemList.count <8}" data-sly-unwrap>
<dt>index: ${itemList.index}</dt>
<dd>value: ${item.title}</dd>
</div>
</dl>
You can use either of count or index variable.
Related
Is there a way to format the numbers on the y-axis the tooltip value? Ex, I want the numbers to be delimited by commas. 1000 -> 1,000. 1000000 -> 1,000,000
You can use the thousands option for this:
<%= line_chart data, thousands: "," %>
In Adobe Business Catalyst, it stores dates in ISO 8601 format E.G. 1989-08-01T00:00:00
They provide a means of retrieving these dates like so:
{module_data resource="customers" version="v3" fields="firstName,middleName,anniversary" skip="0" limit="10" where="\{'id':'{{memberId}}'\}" order="id" collection="crmData"}
Which outputs the following for anniversay:
[anniversary1, 1987-08-01T00:00:00][anniversary1Title, Start Year][anniversary2, 1989-08-01T00:00:00][anniversary2Title, End Year][anniversary3, ][anniversary3Title, ][anniversary4, ][anniversary4Title, ][anniversary5, ][anniversary5Title, ]
I would like to retrieve only the records with a certain year (E.G. 1989). I've tried the following, but I'm pretty sure 'contains' is the wrong way to be going about this:
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'anniversary.anniversary2':\{'$contains':'1989'\}\}" order="id" collection="crmData"}
I can find the record I'm looking for when I hard code the date (including month and year):
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'anniversary.anniversary2':'1989-08-01'\}" order="id" collection="crmData"}
Just need a little help to make this work when I only know the year. Thanks in advance.
This does the trick.
{% assign first = "2016-01-01T00:00:00" -%}
{{first}}
{% assign last = "2017-01-01T00:00:00" -%}
{{last}}
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'$and':\[\{'anniversary.anniversary1':\{'$lt':'{{last}}'\}\},\{'anniversary.anniversary1':\{'$gt':'{{first}}'\}\}\]\}" order="id" collection="myData"}
<div>
<pre>{{myData|json}}</pre>
</div>
Let me know if you need more help.
I am using the GWCODE categories plugin for my sidebar in ExpressionEngine.
Is there a way to only show children (depth_2) categories that have 15 or more entries? I know there a entry_count variable, but I am not certain how to use it in order to filter the output
When using the entry_count variable ensure you specify it as a parameter, otherwise it won't output anything.
{exp:gwcode_categories channel="example" depth="2" entry_count="yes"}
{if {depth} == 2 && {entry_count} >= 15}
{cat_name}
{/if}
{/exp:gwcode_categories}
If you specify/clarify the code you're currently using I can refine the example above.
<!DOCTYPE html>
<meta charset="utf-8">
<title>An HTML5 Document</title>
<p>1
<p>2
<p>3
<p>4
<p>5
<p>6
<p>7
<p>8
<p>9
<p>10
<p>11
<p>12
<script>
// When the document is clicked, codes below should remove all the paragraphs in the page.
// There are 12 paragraphs in the page, but codes below can just remove 6 of them.
document.addEventListener('click', function () {
var i, allParagraphElements = document.getElementsByTagName('p');
console.log('allParagraphElements.length: ' + allParagraphElements.length);
for (i = 0; i < allParagraphElements.length; i += 1) {
console.log('i: ' + i);
allParagraphElements[i].parentNode.removeChild(allParagraphElements[i]);
}
}, false);
</script>
See codes on jsFiddle: http://jsfiddle.net/7NmRh
How can I fix this problem? Thank you.
You iterate from top to bottom:
Iteration one:
twelve paragraphs, index = 0
paragraph at index 0 is deleted and paragraph 1 is now at index 0
Second iteration:
Eleven paragraphs, index = 1
paragraph at index 1 is deleted and paragraph 2 is now at index 1
You see what's going wrong? You only delete half of the paragraphs
Iterate the other way around and all the paragraphs are deleted
JSFIDDLE
.getElementsByTagName returns a live nodelist which is automatically updated as you make changes to the underlying subtree it represents. Basically, when you remove elements the .length is changed as well and the loop will end "prematurely".
You could use .querySelectorAll to get a static nodelist instead.
http://jsfiddle.net/7NmRh/1/
allParagraphElements = document.querySelectorAll('p');
You can also convert the nodelist to an array, which behaves like a static nodelist as well:
allParagraphElements = [].slice.call( document.getElementsByTagName('p') );
http://jsfiddle.net/7NmRh/4/
Friends,
I have written the following JavaScript to ascertain which row of an tabular form the user is currently on. i.e. they have clicked a select list on row 4. I need the row number to then get the correct value of a field on this same row which I can then perform some further processing on.
What this JavaScript does is get the id of the triggering item, e.g. f02_0004 This tells me that the select list in column 2 of row 4 has been selected. So my Javascript gets just the row information i.e. 0004 and then uses that to reference another field in this row and at the moment just output the value to show I have the correct value.
<script language="JavaScript" type="text/javascript">
function cascade(pThis){
var row = getTheCurrentRow(pThis.id);
var nameAndRow = "f03_" + row;
var costCentre = $x(nameAndRow).value;
alert("the cost centre id is " + costCentre);
}
// the triggerItem has the name fxx_yyyy where xx is the column number and
// yyyy is the row. This function just returns yyyyy
function getTheCurrentRow(triggerItem){
var theRow = triggerItem.slice(4);
return theRow;
}
Whilst this works I can't help feeling that I must be re-inventing the wheel and that
either, there are built-in's that I can use or if not there maybe a "better" way?
In case of need I'm using Apex 4.0
Thanks in advance for any you can provide.
Well, what you have described is exactly what I typically do myself!
An alternative in Apex 4.0 would be to use jQuery to navigate the DOM something like this:
var costCentre = $(pThis).parents('tr').find('input[name="f03"]')[0].value;
I have tested this and it works OK in my test form.