# Dynamically construct url param

**URL:** <https://discourse.gohugo.io/t/dynamically-construct-url-param/30828>\
**Category:** support\
**Created:** [January 24, 2021, 9:16am UTC](https://discourse.gohugo.io/t/dynamically-construct-url-param/30828 "2021-01-24T09:16:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mydeveloperpal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mydeveloperpal/32/13212_2.png) [@mydeveloperpal](https://discourse.gohugo.io/u/mydeveloperpal)\
**Post date:** [January 24, 2021, 9:16am UTC](https://discourse.gohugo.io/t/dynamically-construct-url-param/30828/1 "2021-01-24T09:16:00Z")

</div>

Hi,

Am trying to dynamically construct url param from local variable.

```
config.yaml
    params:
         share: 
             url: "example/shareArticle"
             urlParam:
                 url: pageUrl
                 summary: body

```

partials.html

```
{{ $title := .Title }}
{{ $pageUrl := .Permalink }}
{{ $body := print $title " by MyDeveloperPal. " $pageUrl }}

  {{with .Site.Params.share}}
        <div onclick="window.open('{{- .url -}}?{{- range $index, $element := .urlParam -}}{{- $index -}}={{- $element -}}&{{ end }}');">
            share Content
        </div>
   {{end}} 

```

Currently this generates

```auto
example/shareArticle?url=pageUrl&summary=body&

```

But I want to dynamically generates based on the local variables in partials i.e.

```auto
example/shareArticle?url=https://myblog.com/article&summary=Article by MyDeveloperPal https://myblog.com/article&

```

Appreciate your response.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [January 24, 2021, 9:57am UTC](https://discourse.gohugo.io/t/dynamically-construct-url-param/30828/2 "2021-01-24T09:57:48Z")

</div>

> [@mydeveloperpal](#):
>
> `<div onclick="window.open('{{- .url -}}?{{- range $index, $element := .urlParam -}}{{- $index -}}={{- $element -}}&{{ end }}');">`

As per your quoted template, it appears that you can simply add your `$body` variable to the above, to render your desired output.

i.e.

```auto
onclick="window.open('{{- .url -}}?{{- range $index, $element := .urlParam -}}{{- $index -}}={{- $element -}}&{{ end }}{{ $body }}`);"

```

---

<div class="post-metadata">

**Author:** ![mydeveloperpal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mydeveloperpal/32/13212_2.png) [@mydeveloperpal](https://discourse.gohugo.io/u/mydeveloperpal)\
**Post date:** [January 24, 2021, 7:04pm UTC](https://discourse.gohugo.io/t/dynamically-construct-url-param/30828/3 "2021-01-24T19:04:06Z")

</div>

Nope. Thank you @onedrawingperday for your answer.  
Let me rephrase my question.

In config, I have the following map for urlParam  
url: pageUrl  
summary: body

I am trying to iterate the map and generate queryParams where

- key in the queryParam matches the key in the map
- value in the queryParam is populated by the local variable whose name is identified by the value in the map.

For example,  
?url={{ load the local variable pageUrl}}&summary={{ load the local variable body}}&

---

<div class="post-metadata">

**Author:** ![fizzbuzz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/fizzbuzz/32/13392_2.png) [@fizzbuzz](https://discourse.gohugo.io/u/fizzbuzz)\
**Post date:** [January 25, 2021, 8:47pm UTC](https://discourse.gohugo.io/t/dynamically-construct-url-param/30828/4 "2021-01-25T20:47:53Z")

</div>

Hi there.

Not sure I fully understand your case, but if each page has it’s own .Permalink and .Description (or custom equivalent), no need to use Site Params for that. Front matters for the given page should work.

Or maybe you want to variabilize the front matter variables as well ? Not sure that’s feasable.
