Hi,
(new user to rhythmyx)
I am trying to share a single template for 4 different content types. I want the template to say: If I am displaying a content item of contenttype1, show its fields if, content type 2, show fields from content type 2 etc. What macros should I use to do the if condition ?
You can check the name of the content type as defined in Workbench as follows:
$type = $sys.item.definition.internalName;
Once you have this, you can create your logic for different fields.
#if($type=="rffGeneric") {
...
}
Another option, most likely a recommended one, is to define a dispatch template that has the same logic to determine which page template will be used during preview/publish. This will allow you to keep your templates clean and separate as opposed to cluttering up logical conditions within one template.
What’s the use case for using a single template if you’re going to call different fields from different content types?
Thanks for the answer!
A small clarification:
it is
#set ($foo = $sys.item.definition.internalName)
Will look into the dispatch template suggestion.
The use case: I have a page template with a slot in it. I want the user to be able to drop in one or more than one content type (item) into that slot. When the page gets published, all the values for all those content types should be saved somewhere that I can retrieve separately later.
I have hence created these 4 different content types which all have a drop down field. Depending on the content type, the listing in the dropdown will be different. User inserts one or more content items into the slot. My challenge was to display the right field value in the template which is why I was asking how a template can identify the content type first before getting its field value since the field names for the dropdown are different for each content type.
Yep, that’s correct. The syntax should be:
#set($ct_name= $sys.item.definition.internalName)