I'm trying to use a checkbox list for adding values to content i a tag.
I've made a similar function, where I use 2 true/false, but would like to see if it's possible, to just use a checkboxlist instead.
Are these only for adding the value of the checkbox or could you do a if/else statement, to add noindex, if noindex box is checked, and as deafult add index, if it isnt?
Is this possible, or should I stick with the 2x checkbox way?
In all honest it actually depends what you find easiest to process in your front end code. Ease of code is probably separate check boxes, but a nicer editor experience is probably the checkbox list.
There is a third option which is what I've actually done is create my own property editor completely for Robots meta which contains 2 check boxes but it handles the if behaviour in the back office so I can just render out the final value for that field on the front end.
How should I go about, to just get the actual "noindex,follow" (from the example above), printed in my empty tag?
And can I put a default content (index,follow), when neither noindex nor nofollow is selected
Property editors are great things, I highly recommending looking into them more, but remember sometimes it's best to use whats there than build your own. Umbraco strives to keep editor experience simple and fluid so just keep that in mind when thinking about making your own editors :-)
Yea they're awesome, and definitely something I'll look more into.
I aware that sometimes the built-in editors are preferable, but it's fun learning new stuff, and I like that you can style the elements in the back office with the property editors.
Also started doing alot of custom views for different page types, which is also awesome for editors.
Thanks again for suggesting uSEO which was a great starting point to getting started with the property editor.
Using CheckBoxList for meta robots content
Hi guys
I'm trying to use a checkbox list for adding values to content i a tag.
I've made a similar function, where I use 2 true/false, but would like to see if it's possible, to just use a checkboxlist instead.
Are these only for adding the value of the checkbox or could you do a if/else statement, to add noindex, if noindex box is checked, and as deafult add index, if it isnt?
Is this possible, or should I stick with the 2x checkbox way?
Best
Henrik
Hi Henrik,
In all honest it actually depends what you find easiest to process in your front end code. Ease of code is probably separate check boxes, but a nicer editor experience is probably the checkbox list.
There is a third option which is what I've actually done is create my own property editor completely for Robots meta which contains 2 check boxes but it handles the if behaviour in the back office so I can just render out the final value for that field on the front end.
I based it on this existing package but as I wanted to separate components out I effectively created my own version. https://our.umbraco.org/projects/developer-tools/useo-pro/ so it could be worth looking at that :-)
Nik
Hi Nik
Thanks a bunch for your reply.
That's a real nice way to do it.
I haven't worked with Property Editors before, but I followed your advice, and downloaded the uSeoPro.
After looking at the source, I've come up with this so far:
HTML:
Controller:
This works, but my question now is, how to actually get the code into my template. When rendering the field in the tempalte, I get the following:
How should I go about, to just get the actual "noindex,follow" (from the example above), printed in my empty tag? And can I put a default content (index,follow), when neither noindex nor nofollow is selected
Okay. So I did a little trial and error and ended up with the following changes to my controller, and got it working.
So first of I changed a little in the vars, to get index,follow when none of the checkboxes were checked:
Next off, instead of adding to the r1, I set r1 to only handle noindex/index and r2 to only handle nofollow/follow.
I also removed the comma inside the noindex/index, added r1 and r2 to an array and then joined it:
Then for the other part on how to render it in the template, I changed the last object to a string and added the surrounding meta-tag:
The final controller looks like this:
Nice work on getting it working :-)
Property editors are great things, I highly recommending looking into them more, but remember sometimes it's best to use whats there than build your own. Umbraco strives to keep editor experience simple and fluid so just keep that in mind when thinking about making your own editors :-)
Congrats again :-)
Thanks Nik
Yea they're awesome, and definitely something I'll look more into.
I aware that sometimes the built-in editors are preferable, but it's fun learning new stuff, and I like that you can style the elements in the back office with the property editors. Also started doing alot of custom views for different page types, which is also awesome for editors.
Thanks again for suggesting uSEO which was a great starting point to getting started with the property editor.
Have a great weekend!
Best
Henrik
is working on a reply...