# Variables as an object method / Dynamically creating function method name

**URL:** <https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861>\
**Category:** support\
**Created:** [May 23, 2019, 8:02pm UTC](https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861 "2019-05-23T20:02:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martincampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/martincampos/32/5831_2.png) [@martincampos](https://discourse.gohugo.io/u/martincampos)\
**Post date:** [May 23, 2019, 8:02pm UTC](https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861/1 "2019-05-23T20:02:05Z")

</div>

Hello Hugo community,

Perhaps someone might be able to answer my question. I have created a shortcode prints out a table here: [https://gist.github.com/fieldingtron/1530c23a21df29052e2afac26d9af09d](https://gist.github.com/fieldingtron/1530c23a21df29052e2afac26d9af09d)

the shortcode ranges over a front matter parameter  
.  
range $.Page.Params.table

my question is the following – is there way to pass in the variable to range over ?

I have tried

{{ range range (printf “%s%s” “$.Page.Params.” (.Get 0) ) }} to select another table to print out

but I keep getting the error  
execute of template failed: template: shortcodes/table2.html:7:47: executing “shortcodes/table2.html” at \<0\>: range can’t iterate over $.Page.Params.table

Is there a way to dynamically create a function method ?

Any thoughts ?

Thanks in advance anyone

---

<div class="post-metadata">

**Author:** ![madispe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/madispe/32/7325_2.png) [@madispe](https://discourse.gohugo.io/u/madispe)\
**Post date:** [May 23, 2019, 8:03pm UTC](https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861/2 "2019-05-23T20:03:54Z")

</div>

Try `$.Page.Param (.Get 0)`

[(docs)](https://gohugo.io/functions/param/)

---

<div class="post-metadata">

**Author:** ![martincampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/martincampos/32/5831_2.png) [@martincampos](https://discourse.gohugo.io/u/martincampos)\
**Post date:** [May 23, 2019, 8:11pm UTC](https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861/3 "2019-05-23T20:11:33Z")

</div>

> [@madispe](#):
>
> $.Page.Param (.Get 0)

thanks for your quick reply … same error message this time with one letter different

template: shortcodes/table2.html:7:46: executing “shortcodes/table2.html” at \<0\>: range can’t iterate over $.Page.Param.table

my shortcode looks like this below

{{\<table2 “table”\>}}

and the frontmatter field looks like this …

```
table: 
-
  - Name
  - Address
  - Location

```

The shortcode works well when I set the field in code like this below

> range $.Page.Params.table

---

<div class="post-metadata">

**Author:** ![madispe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/madispe/32/7325_2.png) [@madispe](https://discourse.gohugo.io/u/madispe)\
**Post date:** [May 23, 2019, 8:40pm UTC](https://discourse.gohugo.io/t/variables-as-an-object-method-dynamically-creating-function-method-name/18861/4 "2019-05-23T20:40:49Z")

</div>

Make sure you don’t have quotes around the param. I tried with your template and it works for me, when I replace:

```
{{ range $.Page.Param.table }}

```

with

```
{{ range $.Page.Param (.Get 0) }}

```

Note that you can format your table data better by using yaml in-line flow sequence style:

```
table:
  - [Name, Address, Location]
  - [A, B, C]
```
