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.
Related
I want to conditionally show a field in a web forms for marketers form in Sitecore 8.1.
My thoughts was that rules could be utilized to that. the only problem is that it seemingly does not work.
When I set a field to conditionally hide based on the value of another field, nothing happens when I satisfy the condition ie. enter the conditional value.
My intuition here is that the rule editor is not working on realtime on the form (by using JavaScript) but is only something that runs on the server.
Can anybody confirm this? Or otherwise send me the right direction towards realtime updating the form based on rules?
Greetings Mads Buch
You will require to use Javascript. What you can do is to create a custom rule which will be triggered via javascript. You can check the following link on how to create a custom rule https://jeffdarchuk.wordpress.com/2015/06/04/lets-use-that-rules-engine/
Also, you may create a custom type as suggested in this thread.
Thanks
So I am rather new to sitecore, and it's a topic that wasn't covered during my training. My questions is just to help point me to the correct term, or documentation on a method to do the following.
I have a definition item, with a ton of field groups, what I want to do is something like:
if Value of Field X is "yes" then collapse/hide Field X or Field Group X.
Does that make sense? Is it a validation rule? or some other kind of rules, is it a workflow I need to attach? Do you place it on just the field I want to hide, or the field that triggers the action?
I appreciate any guidance.
There is nothing out-of-the-box in Sitecore to achieve what you want but there is no reason you cannot create a composite custom field type to do this. The following articles will help you achieve this:
Creating a custom Sitecore Field
Getting to Know Sitecore: Custom Fields, Part 1
Create a new control, inheriting either from Droplist (if the comparison of the value is to be text based) or Droplink (for comparison of ID). You could add a parameter in the Source field of the control to specify what the values that trigger the hide should be.
The underlying control in the Content Editor is just a standard HTML select element. Add onchange events to the control and add your Javascript handler to hide the other controls. Since I could not find a way of adding additional custom css classes to the Sitecore controls, it would be best/easiest to hide all other controls in the same collapsible group after you control. This would mean you would need to group your controls better (or logically at least).
The Javascript will be something like this (the Content Editor uses the Prototype JS framework):
if ($(this).getValue() == 'no') {
// find the parent container of this control and then hide all the next siblings in the same group
$(this).up('.scEditorFieldMarker').nextSiblings('.scEditorFieldMarker').invoke('hide');
}
You can test this by running the above in the console, change out the keyword this with the id of your field, e.g. $('FIELD2292054').
What I am not sure about is how to trigger the hide on initial load, i.e. when someone returns to an existing item, it may be possible by adding to one of the pipelines, but would be better using a JS solution if possible. I'll have a think about this and get a proper code sample up over the next few days.
EDIT: You can add an event handler to sc:contenteditorupdated to handle the content editor being rel-oaded.
document.observe("sc:contenteditorupdated", myFunction);
I wrote up a blog post and put the code on GitHub if you are interested.
Not sure if you have come across Andy Uzick's this blog post.
He wisely talks about hiding fields in the Content Editor and has also created a Sitecore Module called Hide Field Template Extension which is hosted on the Sitecore Marketplace with the full source code to extend.
After reading through and trying the extension, I do feel that it will not completely resolve your issue (how you have described it in the question).
But it will give you:
A mid-term solution to hide a few unnecessary field that some content editors would not like to view.
Fields that are only required by administrators for admin purpose - to de-clutter these fields could be hidden.
Just one thing to bear in mind that it mentions in the requirements Sitecore 6.5 & 6.6. I have not tested it in Sitecore 7. If you are using Sitecore 7, which I think you are, one could modify the source code and make it work for Sitecore 7.
Have a look and share your findings.
Happy Sitecoring!
In my C++/XAML Windows 8.1 app, I want to use a pushpin to denote a location that the user has selected. The default pushpin is very limited and it doesn't even show all the text I add to the "Text" field of the pushpin.
I really want to show something similar to the default pushpin and under that a textblock with some text.
So I think I have to create a user control and use it as a custom pushpin. However, when I do this the "custom pushpin" doesn't appear on the map at the same location that the user selected. It feels like in order to get it at the same location, I need to get the margins of the user control right through hit and trial. What is the correct way to achieve what I am trying to do?
After playing around a little more, I was able to specify the correct position of the custom pushpin using the following API:
Bing::Maps::MapLayer::SetPositionAnchor(Windows::UI::Xaml::DependencyObject^, Windows::Foundation::Point)
See the API reference here.
I'm running Sitecore 6.5 and having some problems with placeholder settings.
It is my understanding that there are two ways to configure placeholder settings:
Globally (in the placeholder setting item)
On a template by template basis (as part of the standard values)
If I apply my settings globally, everything works as it ought to. However, if I apply the setting to the template itself, it has no effect.
I currently have a ticket with Sitecore Support about this issue, but was wondering if the community here had ever run into something like this before.
Technically it should work. Tried it locally on my Sitecore 6.5 install and it works.
Make sure of following:
That the template is inherited correctly, if you have multiple template inheritance.
Placeholder settings are specified properly on the Standard Values and other thing to watchout is if it takes parameter values.
(You probably know this but...) Use Presentation >> Layout >> Details >> Layout Details >> Default >> Edit on ribbon after selecting the item.
Lastly make sure the Allowed Controls are specified correctly (Renderings, Sublayouts, Web Controls, etc.) in your placeholder.
Last thing to check is if your code has a boolean that is hiding the
placeholder. i.e. FooPlaceholder.Visible = False;
Let us know if any of the above helps.
My particular issue was eventually solved by Sitecore support. As it turns out, in Sitecore 6.5 and earlier, mixed case placeholder names do not function correctly. They provided a patch dll to fix the behavior for our site.
Before digging into my explanation i will summarize my question:
How do I provide the user (editor) with a user-friendly possibility to select a datasource item for sublayouts that are preset on the standard values?
My situation is as follows:
I have a page template, with pre-defined layout on the standard values.
Let's say the layout consists of:
one placeholder "wrapper"
one sublayout "content"
This sublayout is pre-defined on my page template, but can also be placed in the placeholder using the Page Editor.
It needs to have a datasource item that defines a Title and Body value.
Now, if a user adds this sublayout to the placeholder using the Page Editor, he will get a nice interface to select or create the datasource item (see screenshot).
However, if the sublayout was pre-defined on the standard values, it will be added without datasource (I can't pre-set the data source in the standard values because it's still unknown by then).
At that point there seems to be no way to get to that nice interface for selecting or creating a datasource item.
Ideally I want to be able to add a field to my template that can hold a datasource item which the user can select/create using the nice interface. I looked at the datasource field type, which could be an alternative, but it's still not exactly what I want.
Bare in mind that the content sublayout is just an example.
I understand that in that specific case I could solve it by always adding a title/body field to the template which hold the values if there is no datasource, but for my real world problem that won't suffice.
I don't have a whole lot of experience with the Page Editor (with the new way of working with it) so I would like to get some advice on this subject.
According to what you said here:
Ideally I want to be able to add a field to my template that can hold a datasource item which the user can select/create using the nice interface. I looked at the datasource field type, which could be an alternative, but it's still not exactly what I want.
It seems you want an intuitive data source selector interface in the CMS shell similar to the Page Editor-based UI.
Quick answer: Simply put, there's nothing that does this for you in Sitecore.
Longer answer: There are still some options for you, e.g.
Define a global "dummy" data source and set that to be the data source set in in Presentation > Layout Details of the template's standard values. So every time you create a new page, it will always point to that dummy value to show something.
From here you can do a few things:
If the user must use the shell UI and not Page Editor, they can simply create another data source item for the specific page and update that page to point to it using the existing native interface in Layout Details.
Another option is to write an event handler, say for item:created or similar that when you create an item, auto-create a corresponding data source item for this specific page (whether this auto-created item be a sub-items or global item...) then programmatically set this to be the data source. A similar concept is shown in this video by Nick Wesselman: http://www.techphoria414.com/Blog/2012/May/Sitecore_Page_Editor_Unleashed