How can I print out a specific array entry in my template?

  • I'm trying to print out a specific custom variable value of mine in the account stats row. Specifically "customFields" is an array that contains a name/value pairs of custom fields.

    I'd like to print out the customField with the name "karma" (if it exists). Is it possible for the templating system's conditionals to handle that? Something like:

    <!-- BEGIN customFields -->
    <!-- IF == 'karma' -->
        <div class="stat">
        <div class="human-readable-number" title="{customFields.value}">{customFields.value}</div>
        <span class="stat-label">{}</span>
    <!-- ENDIF -->
    <!-- END customFields -->
  • Global Moderator Plugin & Theme Dev

    The way you're using customFields, it's an object, not an array.

    Anyways, the easiest way to fix this is to edit your data to have karma as one of the properties so you can do this instead:

    <!-- IF customFields.karma -->

    Otherwise, you can add a helper (keep in mind you need to do this server side and client side):

    Benchpress.registerHelper('equals', function (root, actual, expected) {
      return actual == expected;

    and do this in your template:

    <!-- IF function.equals,, "karma" -->

    The full BenchpressJS docs (that's our templating system) are located here: BenchpressJS docs

  • @pitaj Thanks, your advice coupled with this post helped me get the syntax right:

  • GNU/Linux Admin

    Good work as always @PitaJ 😄

Suggested Topics

| | |

© 2014 – 2022 NodeBB, Inc. — Made in Canada.