Using a variable for a hash key I am trying to use a lookup table technique I saw in a recent Craft Link List post, but getting errors.
The general objective is to auto-generate button text from an array of possibilities using a Matrix block type as a key. Here is my code:
    {% set buttonText = {
    &quot;video&quot; : &quot;Watch the Video&quot;,
    &quot;podcast&quot; : &quot;Listen Now&quot;,
    &quot;externalLink&quot; : &quot;Visit Site&quot;,
    }   
%}


{# resource is a Matrix fieldtye #}
{% set resources = entry.resource.all() %}
{% for block in resources %}
    {% set text = buttonText[(block.type)] %}
    &lt;div&gt;
        &lt;h2&gt;{{ block.heading }}&lt;/h2&gt;
        &lt;p&gt;{{ block.description }}&lt;/p&gt;
        &lt;a href=&quot;#&quot; class=&quot;button&quot;&gt;{{ text }}&lt;/a&gt;
    &lt;/div&gt;  
{% endfor %}

The problem is trying to figure out how to use variable as a key in this statement: set text = buttonText[(block.type)], where buttonText is the array and block.type is the key. The value of block.type is correct and matches the key in the array, so I am guessing the syntax is wrong, but can't get it figured out.
Thanks for any suggestions!
Your example isn't working because block.type is actually a shorthand for block.type.handle. Use the latter instead and it should work. You can tell this is the case by dumping out block.type - it's not a simple string, it's a great big object.
buttonText[block.type.handle]