Using Sitecore 7 - Is there a way I can specify what the placeholder of a template's control will be based on device?
Example : Placeholder A if the device is Mobile else Placeholder B
This is more to do with positioning the content differently in Mobile than desktop site.
UPDATE
Trayek's answer is great and would sure work. Although, I ended up using a different approach.
In the layout details of my template, I added a control C; set its placeholder as A and added HideBydevice Desktop in the additional Parameters section. Then, I again added control C; set its placeholder as B and added HideBydevice Mobile in the additional Parameters section.
Then in my code, I check HideBydevice parameter's value and hide the sublayout/control, if the parameter's value is the same as Sitecore.Context.Device.Name
This worked for me.
What you can probably do is use Sitecore's Rules Engine, where you can create (or use a pre-existing) Condition
to find out whether you are on a mobile device (to do this, you could use the Mobile Device Detector for instance - although I don't know if that module is supported on Sitecore 7).
Then, you can also use the Action
Set placeholder to value
.
You could also create your own Action instead, of course. All you'd have to do is get the RenderingReference
and simply change the placeholder like so:
var reference = new RenderingReference(this.RenderingID);
reference.Placeholder = "A";
More on this in the Rules Engine Cookbook
Update
I've written a blog post about how to get this done: Read it here.