I am not able to pass the selector parameter in the data-sly-resource (when parameter is coming through some external object like java or through some list object). It does not work even though if i initialize a variable using "use" statement and then pass in data-sly-resource statement. However this is working fine when i am passing the hard coded values.
For example , below code works because it has hard coded value 'test value'
<sly data-sly-test="${item.tileReference}"
data-sly-resource.="${item.tileReference # wcmmode='disabled', selectors='test value',
resourceType='abc/tiles/generic-tile'}">
</sly>
However, below code doesn't pass the parameter value because it is coming through some object. here, 'tile.tileCount' holds the value which i have verified by printing in the html.
<sly data-sly-test="${item.tileReference}"
data-sly-resource.="${item.tileReference # wcmmode='disabled', selectors=tile.tileCount,
resourceType='abc/tiles/generic-tile'}">
</sly>
Turns out that Sightly accepts only String as selectors and passing an int value ignores the selector.
Looks like tileCount is an integer, try using a String value instead to fix the issue (the getter method of tileCount can be made to return a String instead of an int).
Related
In sightly I have initialized the sling model class. Now, I want to call the method from that class. But method name is read from some variable (basically I read method name from other location). When I use that variable it doesn’t work. I know sightly doesn’t allow expression inside an expression, so would like to know if there is an alternative to fit this need.
<sly data-sly-use.detailsModel="org.svc.core.model.DetailsModel"/>
${detailsModel.{methodNameVariable}} - doesn’t work (if the method name is read from some variable)
${detailsModel.methodName} - works (if put the method name directly there)
That really dependes on how you structured your data model and what you want to do with it.
If you want to do something like an if ... else that can be achieved with:
<sly data-sly-test="${condition}">${model.someMethod}</sly>
<sly data-sly-test="${!condition}">${model.otherMethod}</sly>
If you want to do something like a switch ... case:
<sly data-sly-test="${condition1}">${model.method1}</sly>
<sly data-sly-test="${condition2}">${model.method2}</sly>
...
If you want to have a trully dynamic method names then you’re better off with a model that returns a map of values instead of having a number of properties/methods and use the dynamic method name as a key:
${model.details[detailName]}
I've got custom fluid ViewHelper that returns an array, and I'd like to access a value of this array directly in one command.
Currently I'm using two commands:
{vendor:helper() -> v:variable.set(name: 'data')}
Value of foo: {data.foo}
Is there a way to do this in a single command? v:variable.get does not seem suited for this task.
As #Jpsy said, there is the VHS Variable / GetViewHelper.
But the usage should be {v:variable.get(name: '{vendor:helper()}.foo')}.
If you need the returned array of your viewhelper multiple times in your template, it's better to use it the way you already did. Because otherwise you would call the PHP method behind the viewhelper to build and return the array each time you want to access an index of an already previously built array again.
v:variable.get of VHS viewhelpers does exactly what you want:
{v:variable.get(name: 'data.{foo}')}
This returns the item with index {foo} from array data.
You write that you're using a custom ViewHelper.
Can you modify it?
Inside the ViewHelper you can easy assign a Variable with:
$this->templateVariableContainer->add('variable', 'content');
It depends also on what you're really trying to reach. If you want to cicle the array, you should create a different viewhelper
If you want to create the array, and then access all the data in different position, you're looking for the f:alias fluid helper
Int he last situation, where you look a direct access of a property immediately after the helper call and no more about it, you have to change your viewhelper, with an optional value. If the helper recive the value, you return the element, otherwise it returns the entire array
How to get values of multiple checkboxes checked in frontend template with fluid and use these values in action extbase?
Declare the argument in your controller action and give it a type array or an array-compatible type which can be constructed by the PropertyMapper.
Name all fields the same as this argument.
Post the data and use the argument in the controller action.
This is the correct way of receiving an array as value of a controller argument. Accessing it directly from the request is not recommended, unless you also declared the argument on the controller action. Not doing so will bypass important argument processing.
save them in a form and retrieve the POST data trough:
$this->request->getArgument('variable')
I'm using Eclipse JDT AST to parse a given java source code. While parsing the code, when it hits a method invocation, I want to find out whether that particular method returns or sets a value of an instance variable (basically to find out whether the callee method is a getter/setter of the same class of caller method).
E.g.:
public void test(){
//when parsing the following line I want to check whether "getName"
//returns a value of an instance variable.
String x = getName();
//when parsing the following line I want to check whether "setName"
//sets the value of an instance variable.
setName("some-name");
}
I've used the AST plugin also find out a possible path which would help me to refer it from the API, but couldn't.
Please let me know whether this is possible and if so, which approach that would help me to get the required information.
Don't think that there is an api which tells you whether a method is a getter or a setter.
You will have to write code to do this. For a getter, you can probably simply check if the last statement in the method is a return statement which returns an instance variable.
Function in NP API plugin creates NPObject and returns into javascript. Then javascript variable with returned NPObject is used as parameter for some other function of plugin. e.g.
var obj = plugin.GetObject()
plugin.UseObject( obj )
But in second function (UseObject) value of parameter is not original NPObject but NPObject JS wrapper class.
Is there way to get original NPObject from instance of NPObject JS wrapper class?
Short answer: you can't.
More involved answer: Some browsers will give you the originating object, but most these days won't, and there is no way to dereference past their opaque NPObject interface to get back to the underlying object.
Alternate solution: Instead of trying to get it that way, add a unique id to your NPObject and a global map to the pointer. Then when you get an NPObject that you think might be the object, call a method (or get a property) to get the unique ID and then you can look up the pointer.
this is the only method that I've found that works consistently across all browsers.