Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Very Popular

    The five Invision Community CMS Pages templates explained

    Jimi Wikman

    In Invision Community CMS Pages there are five base templates that define how your data is presented on the website.

    1. Category List - What you see when you first enter the page where your database has been added.
    2. Featured Records - What you see when you first enter the page where your database has been added if you have chosen to see featured records.
    3. Record Listing - What you see when you view one of the categories.
    4. Record - what you see when you view a specific article or data item.
    5. Form - what you see when you create or edit an article or data item.

    While all of these are using the same tags, they all have a slightly different starting point. This can be frustrated when you want to add custom fields to your templates and what works in one template does not work in other templates. If you just think about them as different layers of your database that each have their own "address" so to speak, then perhaps this is easier to relate to.

    So these are the "addresses" that each template is using:

    1. Category List - $category
    2. Featured Records - $record
    3. Record Listing - $row
    4. Record - $record
    5. Form - It's complicated 😉

    So if you want to add a custom field to a Record template for example, it will look something like this:

    {$record->customFieldDisplayByKey('CUSTOM FIELD ID', 'display')|raw}          

    Usually we want to wrap this in a condition in case we also have HTML related to this field. This way we can ensure that if the field is empty, we don't get extra code that we don't want.

    {{if $record->customFieldDisplayByKey('CUSTOM FIELD ID')}}
    {$record->customFieldDisplayByKey('CUSTOM FIELD ID', 'display')|raw}

    If we now want to do the same in a Record Listing Template and we add that code to the template, then it will throw an error. The reason is that the Record Template Listing does not know what $record is, much like trying to deliver a package to an unknown address that does not exist on the map.

    So instead we change that code slightly using the correct address:

    {{if $category->customFieldDisplayByKey('CUSTOM FIELD ID')}}
    {$category->customFieldDisplayByKey('CUSTOM FIELD ID', 'display')|raw}

     Now the template will understand what you are trying to do, because you have added the correct "address", making the delivery possible.

    Display |raw?

    You have probably noticed that there are some strange things inside the parenthesis beside the CUSTOM FIELD that says 'display' and then |raw? These are parameters that define what part of the custom field we will actually show.

    When you create a custom field, you have two settings for where and how the field will be presented. These are two toggles called: Show in listing template and Show in display template. Listing template is as you probably can guess the Record Listing template and the display template is the Record template.

    These you can style differently, so what you can do when you insert a custom field into a template is to define which of these two styles you want to use. In some cases, you can add other values here as well, but that is another topic.

    The last part |raw is something you add in case you want to prevent the template from converting the HTML for example into text characters that looks scrambled. If you add this, then the template will print out the information as code, which is often very useful, but can also be a security issue as people could potentially abuse it to insert harmful code into your template.


    Discuss the Guide

    Recommended Comments

    There are no comments to display.

    Please sign in to comment

    You will be able to leave a comment after signing in

    Sign In Now

    • Invision Community Playbook

  • Latest Updates

  • Create New...