How to access parent node properties in sightly? - aem

We'l do in cq5(jsp) by accessing currentNode.getParent().getProperties();
How can we do similar thing in sightly?

You will need to implement a use class extending WCMUsePojo class or a sling model that exposes a method that returns you the properties of the parent node/resource.
Refer here for sling models, also refer to similar question here

You can still access these by ${currentNode.parent.properties}. Unfortunately this will return a PropertyIterator (see docs) and data-sly-list does not currently offer support for iterators.
So you will need to implement a Use API helper to gather those into a collection.

Just use
${currentPage.parent.properties['jcr:title']} or ${currentPage.parent.title}

Related

How to extend for bespoke classes in UI5 (not custom controls)

Using the AMD and module paradigm used by UI5, I want to use separate JS classes in distinct JS files to separate my ajax code from the related controllers.
A foundation class will be concerned with common activity such as generic error handling whilst specific classes extending from this will deal with subject-specific ajax communication only. This will NOT be a custom control so no requirement for render capability, metadata, etc.
I wish to benefit from the sap.ui.define functionality and also want my new class to be good UI5 citizen. For example I want to fire my init when the class is instantiated.
Which sapui5 class or classes should I extend from? I am currently using sap/ui/base/Object but would like to know if there is a better choice based on better performance or better fit to purpose.
I am aware of the documentation on custom controls but this seems to focus only on details of classes that render to screen.
This is the skeleton of my current approach:
sap.ui.define(['sap/ui/base/Object'],
function(BaseObject) {
"use strict";
var AjaxBase = BaseObject.extend("myAjaxBase", {
constructor: function(oControl) {
BaseObject.apply(this);
console.log("AjaxBase.constructor() fires")
}
})
AjaxBase.prototype.init = function() {
console.log("AjaxBase.init() fires")
}
return AjaxBase;
}, true)
You can use sap.ui.define even for objects which do not extend sap.ui.base.Object. So if you do not really need functionality provided by UI5 objects you are not forced to extend them. However, in your case it looks like you want to use event support and in this case it would be useful to at least extend sap.ui.base.EventProvider.
As you want to separate backend calls from your controllers it looks like you are using a JSONModel and have more complex use cases than just reads. In this case you could also extend the JSONModel with support for create, update and delete operations.

How to extend tag.object with new attributes within Adobe CQ5 TagManager API

I want to extend tag.object (TagManager API) with new attributes. By default, every tag.object has three attributes: name, title and description. Is it possible? Has anybody deal with it?
You would need to implement your own TagManager - probably extending the abstract TagManager interface and implementing it.
Have a look at the com.day.cq.tagging.impl package - especially the JcrTagManagerImpl class.
A workaround would be to wrap the tag object and encode the additional properties into the description field.

What does kernel.Bind<SomeType>().ToSelf() do?

I understand the following Ninject registration:
kernel.Bind<ISomeType>().To<SomeTypeImplementation>();
which tells Ninect to fulfill requests for ISomeType by using SomeTypeImplementation.
However I'm not sure what the following is good for.
kernel.Bind<ApplicationDbContext>().ToSelf();
Which was suggested that I use from this question:
What ninject binding should I use?
It makes ApplicationDbContext "self-bindable". If you don't have an interface to bind to, you can bind to the class itself. It's more useful if you add a scope to the call such as:
kernel.Bind<ApplicationDbContext>().ToSelf().InRequestScope();
Any time it sees the ApplicationDbContext that needs to be injected, it will reuse the same object as long as it is in the same HTTP request.
The default scope is transient, which means that any time a class requests ApplicationDbContext it will create a new instance of it. This can be problematic if you have two classes that both need to use the context in the same transaction. That is why you will often see it done with InRequestScope().
By self-binding a type, you enable that type for the following:
Lifecycle Management by the container.
Enable the container to inject dependencies into other types that depend on the self-bound type, and inject dependencies of this type into its instances likewise.
Very useful if you just have one single implementation or you don't need to use abstractions for some reason.

How to implement a site wide class and functions that can be called from anywhere in a Zend Framework Application?

I know there are view controllers and action controllers. I think that view helpers can be used from views and action helpers used from actions in controllers.
I need a class that at bootstrap or wherever, it initializes a number of configuration options, arrays for things like convert month numbers to their names and role numbers to their names.
How can this be achieved?
Put them in a model and use it anywhere you like by instantiating it and calling its helper methods. All model files are auto loaded whenever you call them.
Have a model Constants.php:
<?php
class Constants {
public static function convertMonth($month) {
doLogic();
return $something;
}
}
?>
In your controller or view:
Constants::convertMonth(12);
You could build a Resource Plugin and then add it to yout bootstrap class.
The Constants class or Resource approaches both work nicely. However, I recently had to undo/upgrade a Constants class based solution to meet new requirements, so you might want to consider your future plans before going down those paths.
Specifically, if you ever intend to support multiple languages, or even different words for the constants in different contexts, check out Zend_Translate API docs, Zend_Translate example, or this blog post.

Tell C# to use Castle to create objects

I think my question is a long shot.
Lets say I have an attribute:
public sealed class MyCustomAttribute: ActionFilterAttribute
Used on a class method
[MyCustomAttribute]
public virtual ActionResult Options(FormCollection collection)
Now, I need to add a contructor's parameter
public MyCustomAttribute(IMyDependentObject dependentObject)
{
(...)
}
(You propably notice that it's some Asp.NET MCV code)
I would like to use DI to create this attribute. Asp.NET MVC code automatically create it and I don't know how/where I could write code to use Castle istead.
Any ideas?
As far a I konw castle does not support injection of existing objects, which makes it impossible to inject attributes as their construction is not under your control. Other IoC containers such as Ninject support injection of existing objects. They inject properties of your attribut filter. See http://github.com/ninject/ninject.web.mvc for an extension that exactly does what you need.
What you can do if you want to stay on castle is to inject your own ControllerActionInvoker derived from ControllerActionInvoker (AsyncControllerActionInvoker in case of async controller) into all controllers. In your own invoker you override GetFilters. Additionally to the Filters returned by the base you add FilterInfos that are created by castle.
The decision which filters infos are created and added can be achieved with various strategies e.g.:
Add an own custom attribute that contains the information e.g. name of a binding
A configuration file/database
May you consider switching to MVC3 this makes all a bit easier. As you can register your own FilterProvider which makes all much easier. In this FilterProvider you have to decide which filter info you want to add. See again the two strategies above. See http://bradwilson.typepad.com/blog/2010/07/service-location-pt4-filters.html for information about MVC3 and filters.