If you want to show a custom field inside the category template, then you use this code:
{$record->customFieldDisplayByKey('NAME-OF-FIELD', 'display')|raw}
If you want to only show this when there is a value in the field, then you wrap it in a condition like this:
{{if $record->customFieldDisplayByKey('NAME-OF-FIELD')}}
{$record->customFieldDisplayByKey('NAME-OF-FIELD', 'display')|raw}
{{endif}}
Template Syntax (from IPS Documentation)
Any field you have created can be used within your database templates. This can be done using the following code
{$record->customFieldDisplayByKey('your_template_key', 'viewtype')|raw}
The template key parameter would be whatever you have entered in the 'Template Key' field, in the display tab of your custom field.
The view type parameter is what you would use in order to specify what format you are using, which would depend on which of the options from your display tab in your custom field you wish to show. The view types that can be used are as follows
-
listing - This will show the value as per any listing badge preferences as set up on your custom field. This is usually used within a record list.
-
display/display_top/display_bottom - Each of these show the value as per any display value set up in your custom field. Display on its own will just show the format, however you can use display top and bottom to display based on which of these items is selected within that field for the display section.
-
thumbs - returns an array of \IPS\File objects . Returned only with image types, where thumbnail creation is selected.
-
upload- returns an array of \IPS\File objects . Returned only with upload field type.
-
raw - this will show the value as store in the database, unless there are muliple upload (returned as an array of URLs) or they are a Reciprocal field type (returned as an array of record objects)
- processed - this will show the raw value as specified above, however is also passed through the form helper
Adding |raw will mean that the value will not be escaped. For some items which specifically contain URLs this may be desirable. For example returning a thumbnail, or a youtube item. However if using for items such as plain text, please be aware that you are allowing raw unescaped text to be added to the page.
Recommended Comments
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now