'subclassing' content types

17 views
Skip to first unread message

Arjen

unread,
Aug 10, 2017, 7:46:17 AM8/10/17
to dotCMS User Group
Hi,

Does anybody know if it's possible to create sub types of content, or like 'subclass' content types?
I'd like to be able to create a content type, let's say 'product' and then create two sub types called 'garden product' and 'kitchen product'.

Then I'd like to be able to create a relationship between some other object and a product, where that product could be of any product sub type, so either garden or kitchen.

Is that something that can be done?

If not then I guess I could get away with conditional fields of a content type.
Take for example the same 'product' object but then give it a 'type' property with a radio button value and different fields become available depending on the selected type.
I'm not sure if that's something that's usually done though.

Has anybody else come across these scenarios before?

Arjen 

Arjen

unread,
Aug 10, 2017, 8:04:16 AM8/10/17
to dotCMS User Group
Just to clarify, I have read this older thread from 2014 about the same subject, so I guess the main question is whether any new features have been added since to add this functionality?

Also, in post #2 it's suggested to use Javascript to show/hide fields dynamically.
Would anyone have any pointers how to do this, e.g. where to add the script etc?

Thanks

Xander Steinmann

unread,
Aug 10, 2017, 8:14:49 AM8/10/17
to dotCMS User Group
Hi Arjen,

I've copy-pasted some code from a macro we used to hide fields based on certain settings. I think this is the main code:

<script>
  dojo.require("dojo.NodeList-traverse");
    document.getElementById('$!{field}_tag').parentNode.style.display = 'none';
</script>

Here "field" is the field id you want to hide. You can use velocity/javascript to read other fields to determine what kind of "product" you are working with and which fields you need to hide.
Note that this is "hiding for convenience". You would need a Hook to prevent users from altering fields that they should not be able to alter.

Kind regards,

Xander

Arjen

unread,
Aug 10, 2017, 10:41:03 AM8/10/17
to dotCMS User Group
Thanks Xander,

What do you think would be the easiest way to apply this?
Would it be a good idea to make the dropdown or radio button group a custom component with this (or similar) javascript embedded or is there a different way?

Thanks
Arjen

Mark Pitely

unread,
Aug 10, 2017, 10:46:10 AM8/10/17
to dot...@googlegroups.com
Arjen,

With the advent of the API, you can pretty much do anything you want- you are free from having to use the dotCMS backend to handle your structures. It's still there as a fallback.
You can make a form that can absolutely handle what you asking using just normal HTML + Javascript to interact. It can span multiple content structures on the same form.
So, yes, you could have a type field in the primary structure, and then that type can pull from a 'garden' structure OR a 'kitchen' structure. It can give you that second level of abstraction.

Let's try a second way - a SQL vision; now you can have different tables (Primary, Garden, Kitchen) and you can build a 'view' that merges them for interaction.
Here's code that allows a user to add a comment to a page (not being logged in) to report a typo or something like that. It even allows them to upload a file along side of it (like an image or a word doc) to accompany the comment. It uses some tricks ($VTLSERVLET_URI) to get the page url, and I set the page identifier in javascript on each page (ie. document.identifier='$dotPageContent.inode').
You'd need the other bits, but this is a working example.

function addcomment(){   
   
    var formData = new FormData();
 request = new XMLHttpRequest();
request.onreadystatechange = function() {
 
  if (request.readyState == 4){
        if (request.status === 200) {
          console.log("Create Eiffel Connect:");   
          console.log(request.responseText);
            location.href="${VTLSERVLET_URI}?dotcache=refresh";
           
        } else { 
           console.log("Error", request.statusText); 
        } 
 
}
   
 
};

request.open("POST", "/api/content/publish/1", true);  



var comment=document.getElementById('Comment').value;

var d=new Date();
var mon=d.getMonth()+1;
var day=d.getDay()-1;
var atime=d.getFullYear()+"-"+mon+"-"+day+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
console.log(atime);
//User, PageUrl,Identifier, Highlight, Comment, Reported, ResolvedBy, Resolved
 var dataObj={
          'stName':'ParisContentComment',
          'identifier1' : document.identifier,
          'pageurl' : '$VTLSERVLET_URI',
          'user' : '$reviewuser',
          'useremail' : '$reviewemail',
          'userdepartment' : '$reviewdept',
          'userjob' : '$reviewjob',
          'highlight' : document.highlit,
          'comment' : comment,
          'reported': atime,
          'contentHost':'SYSTEM_HOST'};    
   
 formData.append('json',JSON.stringify(dataObj));   
 
var theimager=document.getElementById('tpic');

var file=theimager.files[0];

if (file)
formData.append("document", file);
 

 request.send(formData);  
  
         

}









Mark

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/8d86c475-dd84-43d5-ba22-ddc93142cc9f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Xander Steinmann

unread,
Aug 10, 2017, 11:12:23 AM8/10/17
to dotCMS User Group
Mark has a point: you can do anything you want, but the more you want the more work you will need to do. If you want to stick to the basic dotCMS edit content form then hiding with javascript is an easy way to accomplish what you want. And yes, in a Custom field with a radio/pulldown or something would work fine.

Kind regards,

Xander






Mark Pitely

unread,
Aug 10, 2017, 11:36:41 AM8/10/17
to dot...@googlegroups.com
Hah, yes. You have to do your own verification, etc.
So, choose your poison-  either writing javascript within dotCMS's dojo implementation with some Velocity and some tricky custom fields to *slightly* extend the system OR write more generic javascript to  control your custom experience. I've done them both - it really depends on the process you want. For a simple lookup to do a dropdown that originates in a separate structure, they work great.
So, do you need a piece of glue or do you need an app?

I'd also guess that 'custom fields' as they stand are more likely to be deprecated than the API. They are flakier to handle as you have to do them within the backend and harder to debug. But quicker, with no reinvention of the wheel.
You could also (shudder) use java and webhooks... where's Chris to suggest it?


Mark

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.

Arjen

unread,
Aug 10, 2017, 12:52:39 PM8/10/17
to dotCMS User Group
Hi Mark, yes I do agree with you fully.
We're actually working on a complete bespoke portal which will include these features, but in the mean time we'll have to use the existing interface so if a quick javascript tweak will do it that perfect for now.

Thanks for the example code though, we'll definitely use that for the portal.

Arjen

On Thursday, August 10, 2017 at 4:36:41 PM UTC+1, Mark Pitely wrote:
Hah, yes. You have to do your own verification, etc.
So, choose your poison-  either writing javascript within dotCMS's dojo implementation with some Velocity and some tricky custom fields to *slightly* extend the system OR write more generic javascript to  control your custom experience. I've done them both - it really depends on the process you want. For a simple lookup to do a dropdown that originates in a separate structure, they work great.
So, do you need a piece of glue or do you need an app?

I'd also guess that 'custom fields' as they stand are more likely to be deprecated than the API. They are flakier to handle as you have to do them within the backend and harder to debug. But quicker, with no reinvention of the wheel.
You could also (shudder) use java and webhooks... where's Chris to suggest it?


Mark
On Thu, Aug 10, 2017 at 11:12 AM, Xander Steinmann <xan...@isaac.nl> wrote:
Mark has a point: you can do anything you want, but the more you want the more work you will need to do. If you want to stick to the basic dotCMS edit content form then hiding with javascript is an easy way to accomplish what you want. And yes, in a Custom field with a radio/pulldown or something would work fine.

Kind regards,

Xander






--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.

To post to this group, send email to dot...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages