How do I determine the length of a list in RedDot/OpenText? - content-management-system

I have a page with a list element attached. How do I determine the number of items in that list? Can use render tags, asp, or any other technique (so long as it works!)

Reading the render tags documentation I believe it may be possible to do this in a nicer way
So getting the list Element using this
Context:CurrentPage.Elements.GetElement(lst_myPages).Value
The Value property should return a page collection for list items so you should be able to do
Context:CurrentPage.Elements.GetElement(lst_myPages).Value.Count

<!IoRangePreExecute>
<% lst_myPagesSize = 0 %>
<!IoRangeList>
<% lst_myPagesSize = lst_myPagesSize + 1%>
<!IoRangeRedDotMode><!--[if !IE]><%lst_myPages%><![endif]--><!/IoRangeRedDotMode>
<!/IoRangeList>
<!/IoRangePreExecute>
I think this is the fastest way.
First counter = 0. Then in the list range increment the counter (keep in mind to include the list place-holder too in that block). After that you have the value in the counter.

Apparently, the only way to do this is to loop through the list, counting each item, e.g.
<reddot:cms>
<foreach itemname="testList"
object="Context:CurrentPage.Elements.GetElement(lst_myPages).Value"
countername="listCounter">
</foreach>
</reddot:cms>
The length is then available as:
<%!! Store:listCounter !!%>

In OpenText use this render tag to get the length of a list (name of list element: lst_Navigation):
<%!! Context:CurrentPage.GetElementByName(lst_Navigation).GetLinkedContents().Count !!%>
Context/RDObj: by ObjectLoader Context (alias: RDObj) you get access to objects of Management Server
CurrentPage: returns Page objekt from current page
GetElementByName: method from page object to get a page element by name
GetLinkedContents: returns a LinkList object
Count: returns the number of LinkList elements

Related

TYPO3 meta description - Use closest

I have set the description meta using:
page.meta.description.field = description
Can I make it so child pages use the description from the closest page that has one set?
So if the root page has description1 then all sub-pages use it, unless a sub-page has it's own description2 in which case it and any sub-pages of it would use description2 and so on...
two parts:
in your typoscript:
page.meta.description.data = levelfield:-1, description, slide
in your Install-Tool add the field to the fields which should slide:
$GLOBALS['TYPO3_CONV_VARS']['FE']['addRootLineFields'] = 'description';
added:
aside from straight slide to first non empty entry, you also have options to collect all the entries along the rootpath:
.slide If set and no content element is found by the select command, the rootLine will be traversed back until some content is found.
Possible values are "-1" (slide back up to the siteroot), "1" (only the current level) and "2" (up from one level back). Use -1 in combination with collect:
.slide.collect: (integer /stdWrap) If set, all content elements found on the current and parent pages will be collected. Otherwise, the sliding would stop after the first hit. Set this value to the amount of levels to collect on, or use "-1" to collect up to the siteroot.
.slide.collectFuzzy: (boolean /stdWrap) Only useful in collect mode. If no content elements have been found for the specified depth in collect mode, traverse further until at least one match has occurred.
.slide.collectReverse: (boolean /stdWrap) Reverse order of elements in collect mode. If set, elements of the current page will be at the bottom.
You should not do this - you will get a bunch of error messages in the google webmaster tool complaining about duplicate meta tags. Google dont like this ... it is a kind of duplicate content.
Watch this video from google evangalist Matt Cutts: http://searchengineland.com/googles-matt-cutts-dont-duplicate-your-meta-descriptions-177706
"In short, it is better to let Google auto-create snippets for your pages versus having duplicate meta descriptions."

Get current index of for tag in jsrender

Is there any way to get the current index of for tag in the tag.
Need an solution
{{for ~ID=#index}}
{{:~ID}}
{{/for}}
It will not work because #index is accessible only within the for loop.
Working Code:
{{for}}
{{:#index}}
{{/for}}
And is there any way to access the Jsonobject key and value in for tag instead of prop tag.
{{for arrayOfObj}}
{{:#data.key}} //In here data is a jsonobject.
//I need an key and value of this object.
{{/for}}
Thanks in advance.
Your question isn't very clear. You have an array of objects - OK so what do you want to do?
If you want to iterate over the array you can write {{for arrayOfObj}}...{{/for}}.
Now, inside that block you can get the index and the object. If you want to get a specific known key (if you know the object has a name property for example) you can write {{:name}}.
But if you want to iterate over all of the properties of each object, you can use {{props}} (for each object, within the {{for}} block):
{{for arrayOfObj}} - iterate over array
{{:#index}} - this is the index in the array
{{:name}}
{{props}} - iterate over props of this object
{{:key}}
{{:prop}}
{{:#getIndex()}} - this is the index in the array
{{/props}}
{{/for}}

Wicket - can you specify markups IDs for elements inside repeaters?

I'm having a hard time testing our Wicket application using Selenium because of the random markup ids.
For individual elements, I can use abc.setOutputMarkupId(true).setMarkupId("myId")
to set their markup id explicitly.
But what if the element is added dynamically using a repeater (like ListView)? Is there a way to specify how the markup id sequence should look like?
Well, can't you do the same thing with ListView? If you make your own ListView implementation, and then in the populateItem(final ListItem<?> listItem) method, on that respective listItem you do:
listItem.setOutputMarkupId(true); // write id attribute of element to html
listItem.setMarkupId("id"+i);
where i is some index you initialize in the ListView's constructor or something?
as Andrei told that its possible but dangerous.
setMarkupId doc:
Retrieves id by which this component is represented within the markup. This is either the id attribute set explicitly via a call to
org.apache.wicket.Component.setMarkupId(java.lang.String), id
attribute defined in the markup, or an automatically generated id - in
that order. If no explicit id is set this function will generate an id
value that will be unique in the page. This is the preferred way as
there is no chance of id collision.
http://www.kiwidoc.com/java/l/p/org.apache.wicket/wicket/1.4.0/p/org.apache.wicket/c/Component#top
and also you cant get the markup id with getMarkupId()

jQuery: Select all 'select' elements with certain val()

Does anyone know of an easy way, using jQuery, to select all <select> elements whose val() attribute yields a certain value?
I'm trying to do some validation logic and would like to just select all those elements with a single selector, then apply a warning class to each of their parents. This I know how to do once I select all the elements, but I didn't see a selector that handles this case.
Am I going to have to select all of the <select> elements into a selector, then iterate through them and check each of their values? I was hoping there would be a simpler way.
Thanks.
Why doesn't select[value=x] work? Well firstly because <select> doesn't actually have a value attribute. There is not a single value of a select box: there may be no selected options (there shouldn't normally be, but there can be in at least IE), and, in a <select multiple>, there can be any number of selected options.
Even input[value=x] doesn't work, even though <input> does have a value attribute. Well, it does work, it just doesn't do what you think. It fetches the value of the value="..." attribute in the HTML, not the current value you have entered into the form. The value="..." attribute actually corresponds to the defaultValue property and not value.
Similarly, option[value=x][selected] doesn't work because it is checking the <option selected> attribute from the HTML source (selected attribute -> defaultSelected property) and not the current selectedness of the option (selected property not attribute) - which might have changed since the page was loaded.
Except in IE, which gets the value, selected etc form attributes wrong.
Except (again): Tesserex's example may seem to work, and the reason for that is that that it's using a non-standard jQuery-specific selector, :has. This causes the native querySelectorAll methods of modern browsers to fail, and consequently jQuery falls back to its own (native JavaScript, slow) selector engine instead. This selector engine has a bug where it confuses properties for attributes, allowing [value=x] to do what you expected, and not fail like it should! (Update: this is probably no longer the case in newer jQuery versions.)
Summary: form field state checking and selectors don't mix. Apart from these issues, you also have to worry about escaping issues - for example, what if the value you want to test against contains quotes or square brackets?
So instead, yes, you should check it manually. For example using a filter:
$('select').filter(function() {
return $(this).val()==='the target value';
}).parent().addClass('warning');
(There is a value property in HTML5 and supported by modern browsers, that when you read it gives you the value of the first selected <option>. jQuery's val() is safe to use here because it provides the same method of getting the first selected option even on browsers that don't support this.)
The existing answers don't work on select tags, but I found something that does. Ask for a select that has a selected option.
$("select:has(option[value=blah]:selected)")
You can use :
$("select[value=X]");
where X is the value against which you want to check the select's value.
Attribute selectors Is what you're looking for I believe.
Something like $+('element[attribute="value"]')
See also:
*= anywhere
^= starts with
$= ends with
~= contains word
etc.
You can create a change event that puts the value in a custom attribute on the select element whenever the value changes. You can then use a simple selector to find all of the select elements that have that value. For example:
$("select").on("change", function (e) {
var $select = $(e.currentTarget);
$select.attr("select-value", $select.val());
});
And then you can do this:
var $matches = $("select[select-value='" + searchVal + "']");
$matches will have all of your matching selects.
This is a lot easier than having to iterate through elements. Remember to set select-value to the initial value when rendering the page so you don't need to trigger a change event for each select so the select-value is set.

Prototype js get element with certain value

I am scraping some data and I want to get the the value of an element after a specific tag with value.
It's a bold tag with value 'Types:'.
<b>Types:</b>
Once I get to that element I can use Prototype's Element.next() to get the data I want.
How exactly do I do this?
I have been fiddling with $$ but can't seem to get it right..
Thank you!
Return the first b element with value "Types:":
$$('b').find(function(n){return n.innerHTML=="Types:"})